Commit graph

291 commits

Author SHA1 Message Date
Daniel Verkamp
1fb95746de vm_control: use mmio_allocator_any() to find allocs
The vm_control requests that allocate memory from an existing PCI BAR
previously hard-coded MmioType::High, but we can decouple this from the
particular region by using `mmio_allocator_any()`, which will search
both the low and high MMIO regions. Only one will contain the specified
PCI address and BAR combination, so there should be no change in
behavior for the usual configuration where the PCI BAR will be allocated
from high MMIO.

BUG=b:178000549
TEST=Start crosvm with fs device and GPU enabled

Change-Id: Ia7c5633ee77be0721341d199b704a443c8a3e8d1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784343
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
2022-08-02 00:49:14 +00:00
Daniel Verkamp
600ad38ff8 Remove redundant {self} imports
- Remove trailing ::{self} on all use statements
- Remove any resulting single-level use statements (e.g. use libc;)
- Reformat with `tools/fmt --nightly`

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

Change-Id: I8afd1b0458ca6d08d9b41a24583f7d4148597ccb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3798973
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-08-01 21:27:54 +00:00
Dennis Kempin
4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00
Zihan Chen
11812a5bf9 crosvm: Make ballooning a compile time feature
Balloon support can not be compiled out, and don't need to be
disabled at run time.

BUG=b:235887451
TEST=Guest has balloon device by default, does not have balloon
device when disabled. Ballooning via cli functions by default,
return not supported when running vm has ballooning compiled out.

Change-Id: I737851496fe4c14cdbb69c48e6edf1ca9186c15a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3786928
Tested-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2022-07-27 19:21:50 +00:00
David Stevens
3426ed71c9 wl: switch to shared memory regions
Switch virtio-wl to the new shared memory APIs.

Using the shared memory APIs requires establishing mappings based on
shm offset rather than raw pfn. This means virtio-wl needs to manage its
shmem address space itself, rather than relying on
VmMemoryDestination::NewAllocation. To maintain compatibility with older
drivers, a feature bit is used to determine whether drivers expect
mappings to be specified by shm offset or by pfn.

BUG=b:201745804
TEST=launch crostini gui app
TEST=crosvm device wl --wayland-sock $XDG_RUNTIME_DIR/wayland-1 --socket /tmp/vhost.sock
TEST=crosvm ... --vhost-user-wl /tmp/vhost.sock ...

Change-Id: Ia559de7107130440c8f81a30aab1f6b061d15118
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3765014
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
2022-07-25 11:34:45 +00:00
David Stevens
e9673a428a wl: allocate dma-bufs in process
Directly allocate dma-bufs within the virtio-wl process and remove the
VmMemoryRequest::AllocateAndRegisterGpuMemory type. This is preparation
for migrating to the SharedMemoryMapper interface.

BUG=b:201745804
TEST=Launch arcvm, launch gedit w/crostini, launch gedit w/vhost-user-wl

Change-Id: I232f1fd3dfdb8d7ed068c6b3c2ea23f35d0ddabc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3765012
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Tested-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-07-22 02:28:09 +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
Daniel Verkamp
1dbe52fac4 vm_control: clarify that USB attach only uses dev_path
The bus/address and vendor/product IDs are unused internally; only the
usbdevfs device path matters. Update the internal API parameters and
documentation to match.

The crosvm_control `crosvm_client_usb_attach()` function must keep the
extra parameters to maintain API compatibility, but its documentation is
updated to note that they are unused.

BUG=None
TEST=Attach USB device to Crostini on trogdor

Change-Id: I7086f61a420be1dbf3dd1877fa86a5e82c0c5c77
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708640
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-17 23:18:24 +00:00
Daniel Verkamp
fb641f67e4 resources: introduce AddressRange type
The AddressRange type is used for representing contiguous memory or I/O
address ranges, mostly equivalent to RangeInclusive<u64> but with the
added benefit of implementing Copy and not carrying an extra field used
only for iteration, which we don't need.

Using an inclusive range means we can represent the full address space
with no weird corner cases around the upper limit of the range (for
example, an AddressRange covering the full 64-bit space can be
represented as start: 0, end: u64::MAX).

AddressRange also replaces the previous MemRegion type, which was a
start/size pair.

This normalizes the interface of the resources crates to use
AddressRange rather than a start/size pair; more cleanups throughout the
tree may be possible, but this commit attempts to be somewhat smaller to
have a hope of being reviewable.

BUG=b:222769529
TEST=tools/presubmit --all
TEST=cargo test -p resources

Change-Id: I8c90bdc28456221b5107ef7e589233315ea739c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3696671
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-16 20:29:26 +00:00
Daniel Verkamp
441b6c71f0 vm_control: use open_file() for /proc/self/fd handling
Replace an open-coded version of base::open_file() to simplify the
vm_control code that opens USB devfs files, and improve the error
message when opening the device fails.

Also clean up unused ModifyUsbError variants while we're here.

BUG=b:213152502
TEST=Share USB device with Crostini on trogdor

Change-Id: I9d220487a77a0b83fbc1602f65455e6f384f4abe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3706097
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-06-15 19:44:51 +00:00
Vikram Auradkar
7874d2011e vm_control: Upstream windows patches and enable tests
BUG=b:213152502
TEST=presubmit after enabling vm_control tests

Change-Id: Ie4709dfeb428c527091447bd6f0bda2c14b5492e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3698049
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-06-13 17:34:44 +00:00
Anton Romanov
9ac4427d7b crosvm: vm_control: make handle_request generic over AsRef<Path>
All the Path::new(string var) are very repeptitive and completely
unnecessary

Change-Id: I05e86bcf9ad35519cd74ed8de78c4ddabd88abe0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3680296
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-06-07 20:19:34 +00:00
Hikaru Nishida
4f5ba4bd28 Revert "crosvm: remove balloon stats request timeout"
This reverts commit 56c0d02760.

Reason for revert: Break ARCVM after suspend/resume

BUG=b:234067421
TEST=Checked that ARCVM kept working after suspend/resume

Original change's description:
> crosvm: remove balloon stats request timeout
>
> It was done to avoid deadlock when stats are requested before guest is
> up. Implement a stub BalloonStats::NotReady replier until host is up so
> that timeout is no longer necessary.
>
> BUG=b:232289535
> TEST=few tast crostini/arc tests
>
> Change-Id: I6731b4ee9eaecdd65aebdd3f530f0932b0660c85
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652887
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Anton Romanov <romanton@google.com>
> Auto-Submit: Anton Romanov <romanton@google.com>

Bug: b:232289535
Change-Id: Iffafaef1e1136ebc050d69d001d384eedd0a2319
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3686789
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Hikaru Nishida <hikalium@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Hikaru Nishida <hikalium@chromium.org>
2022-06-02 11:09:31 +00:00
David Stevens
35ce872a45 devices: virtio: iommu: check for invalid attaches
Check that the same mapper isn't used for multiple domains. This ensures
that there won't be mapping collisions/leaks if the guest tries to use
the same mapper with multiple domains.

BUG=None
TEST=Boot ManaTEE with devices managed by viommu

Change-Id: I45889e6fe020c3a24b355fc05a8f74734bece78a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3641221
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-06-01 08:46:38 +00:00
Grzegorz Jaszczyk
cadc84b32a crosvm: extend suspend commands about generating sleepbtn event
As a part of full guest suspension/resumption support extend crosvm
suspend command about generating sleepbtn press. This allows to emulate
PM1 and inject the vSCI to the guest. When the guest kernel is built
with ACPI button support enabled, it allows to suspend guest with use of
some guest daemon listening on ACPI events e.g. acpid
(acpid detects the ACPI sleepbtn event and triggers the guest
 suspension).

During suspension process (VmRequest::Suspend), before VmResponse::Ok is
advertise, there is need to wait for actual guest suspension.
This is required, e.g. when crosvm suspend command is triggered
automatically by vm_concierge during host suspension process and
prevents suspending host before the guest is suspended.

Above is achieved by taking advantage of KVM_SYSTEM_EVENT_S2IDLE
request sent by hypervisor on behalf of a non-privileged VM. It is used
to wake up blocked thread, which is awaiting non-privileged guest
suspension to finish.

The enhanced suspend process introduced by this patch is triggered
only when the --s2idle flag is passed.

BUG=b:194391015
TEST=Suspend the guest by issuing "crosvm suspend
/run/vm/vm.<hash>/crosvm.sock" and make sure that the guest actually
triggers suspend process and finalizes it.

Change-Id: I38cf5a786275fc4afa4ba7642ef0be779f8f1548
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602869
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-27 18:59:16 +00:00
Grzegorz Jaszczyk
2e7ded3fbd crosvm: extend resume commands about generating powerbtn event
As a part of full guest suspension/resumption support extend crosvm
resume about generating powerbtn press during resume. This allows to
emulate PM1 and inject the vSCI to the guest. When the guest kernel
is built with ACPI button support enabled it allows to wakeup guest from
suspend (ACPI powerbtn fixed event is registered for the guest kernel
and since SCI is wakeup armed it allows to wakeup the guest).

Complementary patch for suspend: CL:3602869

The enhanced resume process introduced by this patch is triggered only
when the --s2idle flag is passed.

BUG=b:194391015
TEST=Suspend the guest by "echo mem > /sys/power/state" and wake it up
by issuing "crosvm resume /run/vm/vm.<hash>/crosvm.sock".

Change-Id: Ifa6626801b495cf96508531783c556804d5a51c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602868
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-27 18:43:30 +00:00
Anton Romanov
56c0d02760 crosvm: remove balloon stats request timeout
It was done to avoid deadlock when stats are requested before guest is
up. Implement a stub BalloonStats::NotReady replier until host is up so
that timeout is no longer necessary.

BUG=b:232289535
TEST=few tast crostini/arc tests

Change-Id: I6731b4ee9eaecdd65aebdd3f530f0932b0660c85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3652887
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
Auto-Submit: Anton Romanov <romanton@google.com>
2022-05-19 23:34:28 +00:00
Anton Romanov
0124707336 Revert "crosvm: remove balloon stats request timeout"
This reverts commit 716b698659.

Reason for revert: this is wrong in multithreaded mode

Original change's description:
> crosvm: remove balloon stats request timeout
>
> It was done to avoid deadlock when stats are requested before guest is
> up. Implement a stub BalloonStats::NotReady replier until host is up so
> that timeout is no longer necessary.
>
> BUG=b:232289535
> TEST=few tast crostini/arc tests
>
> Change-Id: Ieb6888487ea5b10664b76d8f94330564e7a3c726
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3647161
> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
> Auto-Submit: Anton Romanov <romanton@google.com>
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Anton Romanov <romanton@google.com>

Bug: b:232289535
Change-Id: I11faa967d6030ad4a0c292069b0678260757fda8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3651672
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-05-17 19:23:48 +00:00
Anton Romanov
716b698659 crosvm: remove balloon stats request timeout
It was done to avoid deadlock when stats are requested before guest is
up. Implement a stub BalloonStats::NotReady replier until host is up so
that timeout is no longer necessary.

BUG=b:232289535
TEST=few tast crostini/arc tests

Change-Id: Ieb6888487ea5b10664b76d8f94330564e7a3c726
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3647161
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-05-17 17:45:21 +00:00
Xiong Zhang
7245ebd353 pcie: hotplug in interrupt for mutli devices
When multi pcie endpoint devices are connected to one virtual pcie
root port as pcie multi function device, virtual pcie root port couldn't
inject hotplug in interrupt for each added pcie device. Only one hotplug
in interrupt is needed for all the added pcie devices.

So this commit adds a hp_interupt field into VfioCommandRequest, only
the last added pcie device sets hp_interrupt to true and requests virtual
pcie root port to inject hotplug in interrupt. Ohter added pcie devices
just create and configure vfio-pci device.

BUG=b:185084350
TEST=Check TBT dock's hotplug in function, TBT dock has multi pcie
devices.

Change-Id: I5a68ec38af9a32de9d4233b48e0aa3681e5a3ba3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3604290
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-05-06 20:33:15 +00:00
Grzegorz Jaszczyk
6b8680bc15 vm_control: minor style improvements for powerbtn command
Minor style improvement - no functional changes.

BUG=None
TEST=Make sure that "crosvm powerbtn /run/<>/crosvm.sock" works as
expected.

Change-Id: Ide843707d69c25c9e0473bc8e55db8c4a6da7553
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3616883
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-01 20:35:34 +00:00
Grzegorz Jaszczyk
ae70c7f3e9 acpi: add support for generating fixed sleep button event from cmd line
Add support for injecting an ACPI sleep button event using the command
line. Upon receiving crosvm sleep command, emulate vPM1 accordingly and
trigger vSCI to the guest if ACPI fixed sleep button event is enabled.

Additionally do not mask the ACPI sleep button event in FADT flags for
the guest anymore. Quoting ACPI specification regarding the sleep button
flag: "If the system does not have a sleep button, this value would be
“1” and no sleep button device would be present".

BUG=b:194391015
TEST=Boot the VM, issue "crosvm sleepbtn /run/vm/vm.<hash>/crosvm.sock",
check guest /sys/firmware/acpi/interrupts/ff_slp_btn counter and if vSCI
was injected. With some additional changes (e.g. acpid on the guest)
suspend guest by issuing sleepbtn command from the host.

Change-Id: Ie50a3a781ba4fbfa04da75186fb5549919a5bd68
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3602867
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Grzegorz Jaszczyk <jaszczyk@google.com>
2022-05-01 20:29:35 +00:00
David LeGare
740c824fe8 Update to gdbstub 0.6.1
Update the GDB stub implementation to the 0.6 version of the gdbstub
crate API, attempting to preserve the current behavior as much as
possible. Hardware breakpoints and single stepping still work, but some
existing issues with software breakpoints are still present.

BUG=None
TEST=Manual

Cq-Depend: chromium:3578400
Change-Id: I522242a1a2055ecdf47b2010a615dc9e0136ebd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3578025
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: David LeGare <legare@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-13 12:52:24 +00:00
Daniel Verkamp
fa0ffe7e81 base: accept AsRawDescriptor in PollContext/EpollContext/mmap
This lets us remove the wrap_descriptor() calls.

A few other places around the tree need to be updated to use Descriptor
instead of RawFd to match the new API.

BUG=None
TEST=tools/presubmit

Change-Id: Ie290f082b50bcf6ae8f77ce6a8b7615fad1be480
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3572770
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-11 20:27:06 +00:00
Vikram Auradkar
0953c58edb upstream a few file from dev/pci
The files include
- coiommu.rs
- msix.rs
- pci_configuration.rs
- pci_root.rs
- pci_bridge.rs
- pvpanic.rs
- stub.rs

Rest of the changes in the patch are supporting changes to build
and test.

Test: presubmit
Bug: b:213149278

Change-Id: Ic8fbcda4ad95370689b232c1656e782ee33425e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3541336
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-04-04 21:49:33 +00:00
Xiong Zhang
1b6e011dab ACPI: Add register gpe notify event interface
Device want to get notification when a specific gpe happens, this commit
add register_gpe_notify_dev(gpe_num, dev) interface into PmResource trait,
so that others could register (gpe_num, dev) into acpi, then they
could get notification at specific gpe trigger.

BUG=b:185084350
TEST=Verify TBT pcie hotplug function in ManaTEE, virtual pcie root port
must get gpe notification during this process

Change-Id: I56eb90361a6b96be364d35c4b6a5ec598a50757e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3539566
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-24 23:41:05 +00:00
Daniel Verkamp
4440db2370 vm_control: refactor VmMemoryRequest
Many of the subtypes of VmMemoryRequest share similar or exactly
identical code, but it is difficult to tell how they differ and what
each variant does. Reorganize the various memory registration requests
into a single RegisterMemory variant with orthogonal source and
destination structures to unify the shared functionality into a single
implementation.

BUG=None
TEST=tools/presubmit
TEST=Boot Crostini on trogdor
TEST=Boot Crostini on hatch

Change-Id: I059ce40b90812067e5ec882320ea7c8b6a3cc0fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3470539
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-23 22:41:22 +00:00
Xiong Zhang
5631839e90 pcie: Implement added GpeNotify() trait
When specific GPE event happens, some devices want to get notification.
For example, virtual pcie root port wants to get notification when
acpi hotplug GPE occurs. So virtual pcie root port implements this trait.

When virtual pcie root port gets this hotplug GPE notification, it will
inject a PME into CrOS, CrOS PME handler will wakeup virtual pcie root
port and TBT DMA engine, and forbit them to enter into suspend again
during hotplug process.

Once hotplug process is finished, virtual pcie root port and TBT DMA
engine could be allowed to suspend again.

BUG=b:185084350
TEST=Verify TBT pcie hotplug function in ManaTEE

Change-Id: I6c984e4f81713ad34383f1fb4ea2a5776ac2fccf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3539565
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-23 00:48:38 +00:00
Noah Gold
c286772db8 base: upstream Tube cross platform support.
Upstreams support for Tubes on Windows, splitting Tube into platform
specific files. This contains several critical enhancements:

* POSIX Tubes support multi producer multi consumer configurations, but
  Windows has remained strictly SPSC for each direction. Windows cannot
  support MPMC, and that configuration is not really something we want
  either. To address that, this CL introduces directional Tubes. A
  SendTube is clonable, and a RecvTube is not, which gives us MPSC.

* This CL also fixes multiple interface conflicts that have developed
  between Linux & Windows:
    + send wasn't async on the Linux AsyncTube.
    + send data wasn't passed as owned on the Linux AsyncTube.
    + Adds the 'static constraint for AsyncTube::send on POSIX. This is an
      requirement on Windows.
    + Event::read_timeout doesn't need to take &mut self, and it wasn't
      downstream. This CL switches to &self.

* Adds the missing notifier.rs file in base.

Note that this CL does not attempt to remove balloon's usage of
Tube::try_clone. That's a somewhat involved issue that should be tackled in
its own CL.

Test: tested downstream on Windows & Linux bots, upstream on Linux bots.

Bug: b:221484449

Change-Id: I288dbc1d1e42f8ce08258cdaaf85100ca93721ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3536897
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-03-22 19:00:54 +00:00
Dennis Kempin
ef516189db Refactoring: Move common/base into base
Executes the script in https://crrev.com/c/3530502

BUG=b:223206469
TEST=presubmit

Change-Id: Ibeffdc8de0b2270f070e60bb2de8d9fdc78a2a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530503
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-03-17 00:01:27 +00:00
Peter Fang
3fbf6c21fd acpi: support GPE injection in command line
Support injecting GPE using "gpe x" in the command line.

BUG=b:199383670
TEST=boot Linux kernel and inject GPE via command line

Change-Id: I512a1f3973c5da2ef06b17d5ac7c7981261f2514
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350494
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:22 +00:00
Peter Fang
eb16dd5118 acpi: support vGPE
- Add vGPE registers to ACPIPMResource and inject vSCI when a GPE is
  enabled and its event is received.
- Add a new interface, gpe_evt(), to trait PmResource.
- Always use vGPE, regardless of FADT forwarding.
- Always advertise support for 256 GPEs [1] to reduce code complexity.

[1] "Up to 256 GPEx_STS bits and matching GPEx_EN bits can be
    implemented." 5.6.1, ACPI Spec Version 6.4

BUG=b:199383670
TEST=boot Linux kernel and inspect /sys/firmware/acpi/interrupts/

Change-Id: I97687326e9313c26b84dfacade5c8741719e7841
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350493
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:21 +00:00
Peter Fang
6ca0323c87 acpi: support fixed power button event in command line
Support injecting an ACPI fixed power button event using "powerbtn" in
the command line.

BUG=b:199383670
TEST=boot Linux kernel and trigger a power button event

Change-Id: I5ed57f533fa3d91043491fd1f0695223a139fc7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350492
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:20 +00:00
Peter Fang
072c103be6 acpi: support fixed power button in vPM1
- Add a new trait, PmResource, for PM-related public interfaces.
- Use SCI_INT in FADT as vSCI if FADT is forwarded.
- Inject vSCI if ACPI fixed power button is enabled and a power button
  event is received.
- Disable MPTable generation if FADT is forwarded [1].

[1] MPTable generation in mptable.rs makes certain assumptions about
    SCI which is incompatible with FADT forwarding. MADT takes
    precedence over MPTable in the Linux kernel so hopefully things
    should work correctly.

BUG=b:199383670
TEST=boot Linux kernel and shut down

Change-Id: Icc93c3e7492e44b3a5badc5e75373c472c9b9791
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3350491
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Nowicki <tnowicki@google.com>
2022-03-10 16:59:19 +00:00
Daniel Verkamp
578e7cce45 base: remove wildcard and export specific sys_util symbols
As a step toward creating a well-defined base API distinct from
sys_util, remove the wildcard `pub use sys_util::*` and individuall
export just the types, functions, and macros that are intended to be a
part of the public base API.

The only functional change is that the net namespace is flattened into
the top-level base namespace, since it inconsistent with the rest of the
API. (sys_util is not affected and still exports mod net, but base does
not.)

BUG=None
TEST=tools/presubmit
TEST=emerge-hatch crosvm
TEST=emerge-trogdor crosvm

Change-Id: I4028d3489cb3816ec9b8d609b3957db8825eb63d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3500062
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-09 20:50:40 +00:00
Anton Romanov
bed40ad547 crosvm: migrate to Rust 2021 edition
BUG=none
TEST=cq

Change-Id: I0059c970879b78bfd40b6ce58b10debcf154b50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508322
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-03-09 01:16:03 +00:00
Haiwei Li
e2dffbfd1c devices: virtio: iommu: implement the vfio-device hotplug and unplug
When a vfio pci device is hot-plugged in, its vfio container should be
passed to the virtio-iommu worker for later dynamic mapping/unmapping
requests.

BUG=b:185084350
TEST=Boot a guest, hotplug in and out a vfio-pci
device repeatedly

Change-Id: Ia2a9c9ef4a3ee6399d90aa17c6656acb52647663
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3476650
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-05 00:24:15 +00:00
Haiwei Li
dbba029d13 devices: virtio: iommu: add socket between main process and virtio-iommu
A tube channel is needed for the communication between main process and
virtio-iommu worker thread, e.g. passing a vfio container file
descriptor of a hot-pluggable device to the virtio-iommu backend which
is in charge of the mapping/unmapping for the endpoint.

BUG=b:185084350
TEST=Boot a guest with no error

Change-Id: Ib5061e795227040ca400bc9a92df84a27cd26438
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3301703
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-05 00:24:13 +00:00
David Stevens
b5aea72eb7 balloon: add failable balloon adjustment
Add a flag to the adjust command that allows the command to fail. When
this flag is set, a reply is sent with the balloon size at the end of
adjustment.

The flag also changes the semantics of inflation somewhat.  By default,
the balloon driver will indefinitely retry if it fails to allocate pages
during inflation. When the flag is set, the device reacts to puff
failure notifications on the event queue by setting the target num_pages
to the current balloon size, to abort and fail the inflation attempt.

BUG=b:213962590
TEST=manual testing with crrev.com/c/3394436
TEST=check ARCVM balloon still works

Change-Id: Idd606b90550c544ce5bea085f62ac35979679d71
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3394442
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-03-02 01:07:00 +00:00
Vikram Auradkar
ae5118f5c7 Enable windows tests for a few crates
Run tests for sys_util_core, poll_token_derive and balloon_control on
windows.

Using dotfiles to disable/serialize test runs of a subset of crates does
not work well with third party crates as it forces us to commit the dot
file to the crate.

The patch modifies and uses the script that runs linux tests.
This patch also allows us to
- build/test child crate even if parent crate has disabled build/test.
- avoid building crosvm if it is not explicitly specified.

RIP short lived .windows_build_test_skip. You allowed us to run noop
kokoro tests.

Test: py .\tools\impl\test_runner.py --arch x86_64
Bug: b:215610772
Change-Id: Icc6d04ffd7c0c33d4f60aeac16fc7d23881c387d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3459809
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-02-18 03:18:58 +00:00
Anton Romanov
cb3cabe3ba Upgrade rust toolchain version to 1.58.1
Pre 1.58.1 have CVE-2022-21658
Cros toolchain got upgraded to 1.58.1

BUG=None
TEST=cq

Change-Id: I2ce5a08b40bcc4895c4f2ecef83efd4162d67494
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3435385
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-02-04 02:20:36 +00:00
David Stevens
0f924dd693 balloon_control: expose rust API for balloon
Add a crate containing an API for controlling the balloon. This is done
by reusing the API between the control socket and the balloon device.

BUG=b:213962590
TEST=compiles

Change-Id: I5d89d5ebee55162d28ba45ca2c49b7083561b916
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3394440
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-01-28 03:52:35 +00:00
Vikram Auradkar
0108238474 Upstream windows build/test script
The patch also adds files to skip building and testing crates on
windows. When we run
```
tools/windows/build_test.py --skip_file_name .windows_build_test_skip
```

the build/test succeeds without actually doing anything as build/test
for all crates is skipped by creating '.windows_build_test_skip'.

Bug: 213170957
Test: Ran script on downstream repo
Change-Id: Iebd2cea463ee722be4feaed88229e1fb5e9fd6c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3417918
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-01-28 00:55:08 +00:00
Andrew Walbran
3cd9360fac Disable virtio balloon device for protected VMs.
It is not compatible with pKVM and leads to RCU stalls on the host due
to the virtio_balloon thread getting stuck.

BUG=b:215517095

Change-Id: Ibd1c9db53bfa001e07ba6399ff50e9073476017d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3412776
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Andrew Walbran <qwandor@google.com>
2022-01-27 11:23:47 +00:00
Xiong Zhang
c78e72b7cf main: Add hotplug vfio device commmand through control socket
Through control socket, user could request crosvm to hotplug a
vfio pci device.
Hotplug in vfio pci device:
    crosvm vfio add host_pci_device_sysfs_path control_socket_path
Hotplug out vfio pci device:
    crosvm vfio remove host_pci_device_sysfs_path control_socket_path

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: Id66e05ae3da8eb85da49407d69fe1efe7e39fe85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955582
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-01-21 20:48:25 +00:00
Chuanxiao Dong
c41ee08e99 crosvm: Extend VmMemoryRequest to support read_only map
Extend with read_only support so that the user can create a
read-only map for some read-only memory region, like read-only
memory backed MMIO bar.

BUG=None
TEST=Boot a VM

Change-Id: Ia6c1fd365808991f02298f7bbfaac0be8c801f8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292929
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
2022-01-21 07:11:43 +00:00
Xiong Zhang
4fbc554e60 Vfio-pci: Release irq_num at pci device remove
Device gets irq_num from system_allocator when device is added, this
irq_num should return to system_allocator when device is hotplug removed.

this commit adds a ReleseOneIrq interface into VmIrqRequest, it release
one gsi into system_allocator. So vfio-pci device could call it at device
close function.

For msi and msix interrupt vectors, they have irq tube already and could
call ReleaseOneIrq easily.
For legacy INTx, the gsi for vfio-pci's INTx is gotten from host, and this
gsi maybe share with other device, so the commit doesn't release this gsi
at vfio-pci device's remove, otherwise the gsi shared device will be broken.

BUG=b:185084350
TEST=Boot a guest and hotplug vfio pci device repeatedly

Change-Id: Ibcca226b4b5b2092b5bc94bef8219eea82979086
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955580
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-01-06 23:32:54 +00:00
Xiong Zhang
3897cd0a2c devices:vfio-pci: Handle vfio pci device bar reallocation
Vfio pci device's bar are mapped into ept and iommu page table for
hardware acceleration, when vfio pci device is hotplug in the guest,
guest kernel will reallocate the bar, so the old bar address should
be deleted from ept and iommu, and the new bar address should be
added.

BUG=b:185084350
TEST=Boot a vm and hotplug add a device

Change-Id: Icc489917f4c241180bbef412a17917b34fafe7e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2955571
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-11-19 22:10:09 +00:00
Dennis Kempin
8a1c50d5cd Refactoring: Move various general purpose crates to common/
This change contains the results of running

./tools/contib/cargo_refactor.py

This will break the next uprev, and needs to be synchronizized
with the corresponding ebuild changes in https://crrev.com/c/3248925

BUG=b:195126527
TEST=./tools/run_tests

Change-Id: Ied15a1841887bb8f59fba65b912b81acf69beb73
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248129
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-10-29 22:31:43 +00:00
Daniel Verkamp
c42ef90be1 vm_control: convert to ThisError and sort
BUG=b:197143586
TEST=cargo check

Change-Id: Ibf99cd24cc0c246fa1e70f3c91b45bc1716adf41
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105430
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-10-06 21:38:32 +00:00
Udam Saini
38fedb73e5 Revert "vm_memory: Add from_desciptor() in MemoryMappingBuilder"
If we need descriptor for things that aren't file or other shared_memory objects, we can create a separate descriptor change, but it shouldn't be the default.

This reverts commit 533c5c8258.

Reason for revert: this causes conflicts with other platforms.

Original change's description:
> vm_memory: Add from_desciptor() in MemoryMappingBuilder
>
> MemoryMappingBuilder had `from_file()` and `from_shared_memory`, which
> are almost the same. So, this commit adds `from_descriptor()` to replace
> both of the two.
>
> BUG=b:194137301
> TEST=build
>
> Change-Id: Ia13f5e8e0f95a5c32e47dc9b3be13b7a7fa510bf
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159881
> Tested-by: kokoro <noreply+kokoro@google.com>
> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>

Bug: b:194137301
Change-Id: Ie203ee3eb3dcddd41c5e55b6980dc6292eb24f85
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3183183
Auto-Submit: Udam Saini <udam@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Udam Saini <udam@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2021-09-27 16:36:24 +00:00
Keiichi Watanabe
533c5c8258 vm_memory: Add from_desciptor() in MemoryMappingBuilder
MemoryMappingBuilder had `from_file()` and `from_shared_memory`, which
are almost the same. So, this commit adds `from_descriptor()` to replace
both of the two.

BUG=b:194137301
TEST=build

Change-Id: Ia13f5e8e0f95a5c32e47dc9b3be13b7a7fa510bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3159881
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2021-09-22 04:37:44 +00:00
Charles William Dick
4745f03ce0 virtio_balloon shared and unevictable stats
This CL adds support for parsing stats introduced by:
https://crrev.com/c/3115084

BUG=b:198468047
TEST=candy crush runs

Change-Id: I8e258ebf7f2b7dd7a3019f40397c59514e7b18bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3168561
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Charles William Dick <cwd@google.com>
2021-09-22 01:06:43 +00:00
Daniel Verkamp
166d1ddfbe crosvm: fix needless_borrow clippy warning
Tree-wide cleanup of new clippy warning in Rust 1.54 that warns about
needless borrows:

  error: this expression borrows a reference (`&...`) that is
  immediately dereferenced by the compiler

https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

BUG=b:197251702
TEST=bin/clippy # with rust-toolchain = 1.54.0

Change-Id: Ib702ec524d4623d264a00ec11dbc2150c411a67b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3108321
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-08-25 23:02:23 +00:00
Joel Galenson
06392aabd4 Migrate to gdbstub 0.5.0.
BUG=b:191784608
TEST=Build and run atest in Android tree

Cq-Depend: chromium:3073700
Change-Id: I5fcfa166caf8c5a5f759a8f62ef78a293db95f1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3071900
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2021-08-13 18:30:47 +00:00
Suleiman Souhlal
2ac78b9ea0 Add "make_rt" command.
This is used to finally make a "delay-rt" VM's RT VCPUs RT.

BUG=b:142777321
TEST="grep policy /proc/<pid of rt vcpu>/sched" to make sure RT vcpu
    isn't RT until "make_rt".

Change-Id: I73177f8adadf3d1099c2b09871ee9d5feab82587
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2703225
Auto-Submit: Suleiman Souhlal <suleiman@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Suleiman Souhlal <suleiman@chromium.org>
2021-08-11 11:39:31 +00:00
Charles William Dick
5404501966 crosvm fix stale balloon stats
Stale balloon stats results can be returned from a stats request for the
following reasons:
* The initial stats buffer from the guest is posted to the
  balloon_host_tube without a request.
* Balloon stats requests can fail because the balloon device isn't
  completely set up yet; writing a stats request to the tube without
  reading the response.
* Balloon stats requests can time out, returning an error. When the
  balloon stats are eventually computed, they will be queued to the tube
  without a read to consume them.

Possibly other reasons too.

This CL fixes this by adding an id to the balloon stats request. The id
is then returned with the computed stats. When consuming stats results
from the balloon_host_tube, we check that the ID is the one we expect,
if not, we keep reading from the tube until we do.

BUG=b:189282316
TEST=tast run dut multivm.Lifecycle.arc_host

Change-Id: I08e50196a45383b30c9e510b3bacbe32888aef80
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3056310
Auto-Submit: Charles William Dick <cwd@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Charles William Dick <cwd@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Hikaru Nishida <hikalium@chromium.org>
2021-08-06 15:39:15 +00:00
Hikaru Nishida
a0e381b0d8 Change balloon_stats output format to JSON
This CL changes the output format of `crosvm balloon_stats` command to
JSON to ease parsing the result.

BUG=b:181267848
TEST=built and checked the output of crosvm balloon_stats

Change-Id: I4af40237109efdd02b5b70375ef8aa706cf5de55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2914247
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Hikaru Nishida <hikalium@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Charles William Dick <cwd@google.com>
2021-06-15 17:29:30 +00:00
Daniel Verkamp
f1439d444b devices: add "usb" feature for emulated xHCI
Add a default-enabled "usb" feature to allow compiling out the emulated
USB controller and host device provider when not needed (e.g. for
crosvm-direct).

This reduces the crosvm-direct binary size by about 400 KiB.

BUG=b:173824333
TEST=cargo build --no-default-features
TEST=cargo build # ensure xhci controller is added

Change-Id: I1fc0eeb09c647854e5df57cd2fe7e92140256853
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2913136
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-05-24 21:37:22 +00:00
Daniel Verkamp
2940980d2e linux: generalize kick_all_vcpus to send any VcpuControl message
Previously, kick_all_vcpus() would only accept VmControl::RunState
messages; extend it to accept any VmControl message type instead.
This required adding the Clone trait to a few types.

BUG=b:174705596
TEST=./test_all

Change-Id: I3c8c42ee8a96ff151fa8f01ab067931bdff2b7b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2718281
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2021-05-14 05:24:47 +00:00
Daniel Verkamp
7b17f50df9 devices: usb: claim interfaces on device creation
This initializes the claimed_interfaces list at startup (before the
first Set Configuration request).  It also makes it possible to catch
initialization errors earlier in the process of adding a device, before
it is added to the emulated USB hub.

BUG=b:180238956
BUG=chromium:1030778
TEST=Share USB device with Crostini

Change-Id: I6f27ec9b7ff6cda2ff23cadd77611f8ce1cfc89e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2811859
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2021-04-22 17:25:22 +00:00
Gurchetan Singh
f860f50b8a rutabaga_gfx: cross-process Vulkan mappings
In multi-process mode, we currently rely on dma-buf mmap() to
map GPU buffers into the guest.  We usually have to fix the
Mesa driver, and maybe even the kernel to get to work.  That's
"kind of" fine for ChromeOS, which owns the entire stack.

For their Virtual Graphics Interface (VGI) initiative, Android
upstream has requested multi-process mode to work in a
cross-platform, generic way.  Using Vulkan is the only option
that meets the rigorous, uncompromising, strict, meticulous and
bone-crushing requirements of Android upstream.

This has possible two benefits:
  1) We can enable multi-process mode on Nvidia or other
     closed-source drivers, which is nice for Cuttlefish.

  2) On open-source drivers, dma-buf memory is pinned to the
     GTT (amdgpu), even when ideally it can be moved into faster
     vram regions.  This atleast gives the implementation the
     chance to do the smarter and faster option.

We shouldn't run into any SELinux issues since the main crosvm
process is not sandboxed.

Incidentals:
   * Changes vulkano_gralloc to consider integrated GPUs and dGPUs.
     Metadata query is preferred done on the integrated GPU.
   * Update vulkano_gralloc to match top of tree vulkano.

BUG=b:173630595
TEST=used Vulkano allocator and mapped memory into the guest

Change-Id: I78b069c7478d11b3201397894dcccd13bdc61f2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2792042
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2021-04-15 17:58:25 +00:00
Noah Gold
9af97d72fa [base] update/clean mmap interfaces.
This CL addresses some minor issues with the existing interface:
1. from_descriptor is too generic for some platforms that require
   special handling for file/File backed mappings.
2. Nearly all call sites pass either File or SharedMemory. Now
   we just have from_ methods for those types to preserve type
   information.
3. Other platforms require additional fields in MemoryMapping, so a
   tuple struct no longer makes sense.
4. The mmap syscall error message was misleading as we use it for more
   than just the mmap syscall.

BUG=None
TEST=builds

Change-Id: I74c41bad52bb81880a11231cd18f47e233548a24
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2815614
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2021-04-15 02:10:35 +00:00
Kevin Hamacher
6fc5f20fd9 Add FFI library providing control socket access
This allows other languages to communicate directly with the control
socket without having to invoke `crosvm`

BUG=None
TEST=Ran ./run_tests

Change-Id: Icbf5905c41643b080bae3613b73a032467db1c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2772798
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kevin Hamacher <hamacher@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2021-04-08 00:20:01 +00:00
Zach Reizner
d49bcdb081 replace all usage of MsgOnSocket derives
Replaced all usage of MsgSocket with Tube.

BUG=b:176847362
TEST=run_tests

Change-Id: Ie647f79926bc0414c125a776eafe7f60c071bab2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2710324
Auto-Submit: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2021-04-02 15:40:41 +00:00
Gurchetan Singh
293913c01a rutabaga_gfx: rutabaga_gralloc: a shimmering beacon of hope
rutabaga_gralloc is a cross-platform, Rust-based buffer
manager.

The rationale for this change is:

1) For the {cross-domain, wayland} context type, we need to
have a good story for the crucial "wl-dmabuf" feature.  As
minigbm has been thoroughly tested on ChromeOS and currently
powers the "wl-dmabuf" feature, it only makes sense for us to
have a path to minigbm for the cross-domain prototype.  This
will be used by Sommelier.

2) While minigbm allocation works well on Chromebooks, it is
not sufficient for cross-platform purposes.  For their Virtual
Graphics Interface (VGI) initiative, Android graphics
virtualization experts have expressed their desire for a Vulkan
based allocator.  This will to go alongside cros_gralloc in
minigbm, which is considered by many to be the ""world's
premiere gralloc implementation".

3) Android graphics virtualization experts have expressed their
desire for vkMapMemory(..) to be used when crosvm is in
multi-process mode.  Currently, only dma-buf mmap() is supported
for zero-copy blobs in multi-process mode.  dma-buf mmap() is not
guaranteed to work on Nvidia (a "must have" for Cuttlefish) or
any other driver for that matter (we *make* it work for ChromeOS).
Possibly only solution: vkMapMemory ;-)

With these goals in mind, here's a summary of the revelant changes:

* Renamed the {gpu_allocator.rs, GpuMemoryAllocator trait} to be
  {gralloc.rs, Gralloc trait}.

* Moved all GPU allocation out of the resources crate and into
  the rutabaga_gfx crate.  This will allow the resources crate to
  be focused on managing resources for virtual machines.

* Moved the gpu_buffer crate into the gralloc module in the
  rutabaga_gfx crate.  The same functionality is now under
  "minigbm.rs", "minigbm_bindings.rs" and "rendernode.rs"

* Added an optional dependency on vulkano.rs.  vulkano.rs is a safe
  Rust wrapper around the Vulkan api [a].  It's emphasis on type
  safety makes a good fit for crosvm, though there are other high
  quality crates out there (gfx-rs, ash.rs).  Though development
  has slowed down, it should satisfy goals (2) and (3) quite easily.

* Added a system_gralloc implementation based on memfd.  This can be
  used when minigbm or Vulkano features are not used, to replicate the
  highly useful "wl-shm" feature in Sommelier.  Astute observers will
  note this can also enable seamless Wayland windowing without GPU
  features for Android too.  Some minor changes to the base crate were
  needed.

* Cut down on the amount of DrmFormats to the subset needed by
  Sommelier and cros_gralloc.

* Moved checked arithmetic into it's own file.

* Internally renamed to "wl-dmabuf" feature to be the "minigbm"
  feature.  This is because "wl-dmabuf" has a dependency on minigbm.

* Small rutabaga_gfx cleanups

[a] https://github.com/vulkano-rs/vulkano/blob/master/DESIGN.md

BUG=b:146066070, b:173630595, b:150239451
TEST=launch virtual machine with 2D mode
TEST=launch virtual machine with 3D mode
TEST=run sommelier with "wl-dmabuf" and "wl-shm"

Change-Id: I693a39cef64cd98e56d843d3c60caa7983d4d6e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2626487
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2021-02-04 02:35:52 +00:00
Keiichi Watanabe
eefe7fb19e devices: virtio: fs: DAX based shared memory support
Support virtio-fs's DAX (direct memory access) operation which allows the guest
to directly access file pages.
Specifically, FUSE_SETUP_MAPPING and FUSE_REMOVE_MAPPING operations are
supported.

This option can be used by specifing `dax` option when mount a file system in
the guest.

The DAX optoin improved file I/O performance in most cases.
In Fio tests, both of read and write score were improved by 1.3-14x depending on
test cases.
In Blogbench tests, which create many small files, DAX improved the write score
by 1.5x while the read score was reduced to ~25% (20391 -> 4593).

Here is an excerpt of results:
Fio
* seq_read:     10.2x (143528 -> 1464911)
* seq_write:     3.3x (61253 -> 896791)
* rand_read:    11.6x (138753 -> 1612739)
* rand_write:   14.6x (61253 -> 896791)
* surfing_read:  1.3x (98473 -> 127907)
* surfing_write: 1.3x (83309 -> 108089)

Blogbench
* read:  0.23x (20391 -> 4593)
* write: 1.50x (248 -> 373)

BUG=b:147341783
TEST=Run vm.{Blogbench, Fio} with CL:2291856

Change-Id: I4a47c601412ed32d926de6304337e1594252d258
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2108315
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2020-12-16 06:03:54 +00:00
Camilo Jacomet
a9bfcb485c Fixed Clippy or_fun_call warnings in devices/
BUG=chromium:1111728
TEST=cargo clippy -- -A clippy::all -W clippy::or_fun_call passes under
devices directory

Change-Id: I4c9e079df98b50e55a5489cd925fb7b621caf4dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2587191
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Camilo Jacomet <cjacomet@google.com>
Commit-Queue: Camilo Jacomet <cjacomet@google.com>
2020-12-15 05:15:00 +00:00
Chuanxiao Dong
256be3a144 Goldfish battery: add external command interface to set the state
Add a new command "battery" which is used to modify the virtual
battery/ac status.

When there is goldfish battery device model created, the command
is able to sent to the goldfish battery monitoring thread. If no,
the command won't be sent.

The supported commands are:
1. crosvm battery goldfish status <status string> crosvm.sock
2. crosvm battery goldfish health <health string> crosvm.sock
3. crosvm battery goldfish present <number> crosvm.sock
4. crosvm battery goldfish capacity <number> crosvm.sock
5. crosvm battery goldfish aconline <number> crosvm.sock

"goldfish" is the battery identifier to specify which virtual battery
is going to be modified by this command in case there are multiple
virtual batteries in the guest in future. Right now only one goldfish
battery is supported.

BUG=chromium:1050432
BUG=b:137890633
TEST=create VM with parameter "--battery" or "--battery=type=goldfish"
and boot linux guest with goldfish_battery driver enabled. From host
side, execute command "#crosvm battery goldfish status discharging
crosvm.sock" can make the guest receive an interrupt, and the status
sysfs is changed to "Discharging". Also tested the other commands
as well.
TEST=modified values are visible in ARCVM and interrupts are triggered

Change-Id: I82177811a6f2b1960f7895522760ff3b8143163f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2119574
Tested-by: Alex Lau <alexlau@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-12 19:34:04 +00:00
Keiichi Watanabe
23f9471bc3 gdb: Support single-step execution and HW breakpoints for x86_64
Support single-step execution command and hardware-associated breakpoints
command in GDB.

BUG=chromium:1141812
TEST=Set breakpoint with `hbreak start_kernel` and show backtrace

Change-Id: I762565ffc9fb055dd3891e172799c3fc87f7604c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2494327
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-12 08:48:01 +00:00
Keiichi Watanabe
c5262e9fad linux: Support GDB remote serial protocol for x86_64
Add a flag '--gdb <port>' to provide GDB remote protocol interface so
a developer can attach GDB to the guest kernel.
In this CL, we support read/write operations for registers and memories.

BUG=chromium:1141812
TEST=Attach gdb and see register values on workstation and intel DUT

Change-Id: Ia07763870d94e87867f6df43f039196aa703ee59
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2440221
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-11-12 08:47:59 +00:00
Chuanxiao Dong
fd5626c523 Goldfish battery: add the basic battery/ac property emulation
Create goldfish battery device model for guest. Provide the
minimal properties and basic accessing for the golfish_battery
driver in the guest.

BUG=chromium:1050432
BUG=b:137890633
TEST=create VM with parameter "--battery" or "--battery=type=
goldfish" and boot linux guest with goldfish_battery driver
enabled. The goldfish_battery driver is loaded successfully.
The /sys/class/power_supply/battery and
/sys/class/power_supply/ac are created successfully.
TEST=cargo test -p crosvm
TEST=goldfish_battery driver is loaded on ARCVM after crrev.com/c/2519336

Change-Id: Iaafa09e3d7e5664d3db8b7df5295f077ec3f6da9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2119572
Commit-Queue: Alex Lau <alexlau@chromium.org>
Tested-by: Alex Lau <alexlau@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
2020-11-11 13:15:11 +00:00
Dylan Reid
b04926680c linux: Switch from a run mutex to a channel
Using a channel will allow for more complicated messages to be sent to
the vcpu thread. Adding debug support will require being able to process
each message from the main thread. The atomic state worked well when
every CPU needed a message and when transient state changes can be
dropped. Neither of those assumptions will hold true when using this
communication channel for debugging message such as setting and getting
vcpu registers or single stepping a particular cpu.

The run state is now per-cpu so that individual CPUs can be stopped and
stepped by GDB in later commits.

BUG=chromium:1141812
TEST=run a VM

Change-Id: Ibe3b71af0c99057666d30e302090a8a4364c064a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2440219
Tested-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-11-11 08:08:40 +00:00
Michael Hoyle
6a0960a4a7 base: First steps towards universal RawDescriptor
This involves removing RawFd trait implementations from
Event and Timer, and resolving the echoing dependencies from
there.

Ultimately, this results mostly in changes across ioctl
(new thin layer in base), kvm, msg_on_socket, and a few other
areas. As usual, most changes are negligible.

BUG=b:162363783
TEST=./build_test

Change-Id: I47dec94666bc3430fed627b4767919c9cb4fce6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2462330
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-31 07:12:34 +00:00
Michael Hoyle
3038e40a6b base: Refactor mmap to use builder pattern.
BUG=b:165423256
TEST=./build_test

Change-Id: Ia67c1a7fe29b66c9cab38476eecde8c25a55617b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2442569
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-16 07:15:24 +00:00
Michael Hoyle
685316f0bd base: EventFd -> Event renaming
Note the CL size is large entirely due to the rename,
the changes are mostly negligible.

Also making a few small additional changes in sys_util
areas that don't need much attention in base. This includes
typedefing and adding specific imports for areas that don't
require significant interface changes.

BUG=b:162363783
TEST=./build_test

Change-Id: I4a2c9c4cdce7565806ed338e241c6b8c82c855c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2415180
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-10-06 13:50:09 +00:00
Michael Hoyle
a7e38ab421 base: Add shared memory layer to base.
This is very largely boilerplate, but changes some interfaces
to accept different parameters, esp using Descriptor.

BUG=b:162363783
TEST=./build_test

Change-Id: I81b513c0de9448c2de505fe5d3a61a29f4eccb78
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2342591
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
2020-09-30 19:44:40 +00:00
Steven Richman
f32d0b48fd Use hypervisor abstraction to run VMs
Calls to the kvm crate have been replaced by calls to hypervisor and
devices::irqchip.  Plugin is unchanged and still KVM-specific.

x86 creates and configures vcpus on the vcpu thread instead of the main
thread.

Code that still depends on kvm or kvm_sys:

  - crosvm_plugin, plugin, and protos use kvm and kvm_sys if built with
    the plugin feature

  - devices::VfioGroup does a kvm_sys ioctl

  - devices::irqchip and hypervisor use kvm_sys.  hypervisor uses
    kvm::Cap and kvm::CpuId internally for now.

BUG=chromium:1077058
TEST=runs es2gears_wayland on kukui
TEST=runs evince on amd64-generic with kernel and split irqchip
TEST=build_test excluding tpm2
TEST=cargo check --features plugin

Change-Id: I0068e34da6a5ff0079b1237be1958933bf12ffe4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2307711
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Steven Richman <srichman@google.com>
2020-08-11 04:51:34 +00:00
Michael Hoyle
6b19695c81 Add "base" crate and transition crosvm usages to it from sys_util
For now, this crate simply re-exports all of sys_util, but it will
be updated to provide new interfaces when needed. This is the
first step to making crosvm not directly depend on sys_util, so
that we can make the interface changes we need without fear of
negatively affecting (i.e. completely breaking) other usages
within chromeos.

BUG=b:162363783
TEST=./build_test

Change-Id: I7d0aa3d8a1f66af1c7fee8fd649723ef17027150
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2325168
Tested-by: Michael Hoyle <mikehoyle@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Michael Hoyle <mikehoyle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-08-06 18:19:44 +00:00
Dylan Reid
ec058d6c46 vm_memory: A crate to hold vm-specific memory objects
Move GuestAddress and GuestMemory to a new crate for VM memory. This
will make separating sys_util and crosvm independent making it easier
to use sys_util functions outside of crosvm.

Change-Id: I12e14948ea85754dfa6267b3a3fb32b77ef6796e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2311251
Auto-Submit: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-24 21:42:34 +00:00
Lingfeng Yang
d6ac1ab3a7 kvm: allow registering memory from current address space
This is good for enabling non-exportable Vulkan host coherent memory,
along with anything else where an exportable OS object isn't supported.

This CL introduces:

1. ExternalMapping, which wraps an external library mapping using
function callbacks, for purposes of sharing device memory to the guest
in the case where the device memory is not compatible with the mmap interface.
This is common in Vulkan when VkDeviceMemory is host visible but not
external, or external but based on an opaque fd.

The lifetime of the library mapping is tied to the lifetime of the
ExternalMapping.

2. Usually, we would send such memory requests over a socket to the main
thread. However, since these new objects require more metadata than
other requests that are sent over the wire (because there's information
about inheritance and refcounts), we also plumb the "map_request" field,
which wraps a single ExternalMapping.

Note that this ExternalMapping will not work in the sandbox case. In the
sandbox case, we will then have to figure out how to serialize/deserialize
ExternalMapping requests over a socket.

BUG=b/146066070, b/153580313
TEST=compile and test

Change-Id: I3b099b308aec45a313a8278ed6274f9dec66c30b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034029
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-07-24 00:19:11 +00:00
Gurchetan Singh
014b351f58 resources: add address_from_pci_offset function
Refactor current code and add tests.

BUG=chromium:924405
TEST=compile and test

Change-Id: I9476f3a4ffd8ae85fc95d6889ada6b056613bbfa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216447
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2020-06-12 05:00:42 +00:00
Gurchetan Singh
173fe62df2 kvm: use MappedRegion trait
- Reduces code duplication between MMIO and mmap arenas
- Makes adding future types easier
- Makes upcoming deprecation of kvm crate easier
- Use BTreeMap instead of HashMap since it's more efficient

BUG=chromium:924405
TEST=compile and test

Change-Id: I520abed0926489e64aac046e0dc0cfeb72fae7b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216446
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Steven Richman <srichman@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2020-06-12 05:00:37 +00:00
Steven Richman
7c359d617f hypervisor: add Vm user memory region functions
The separate Vm functions for MemoryMappings and MemoryMappingArenas
have been combined and now use a MappedRegion trait that the mappings
implement.  msync_memory_region replaces the get_mmap_arena function,
which is used by VmMsyncRequest.  Since Vm uses mutexes for cloning, it
can't return mem region references.

BUG=chromium:1077058
TEST=cargo test, cargo test -p sys_util, cargo test -p hypervisor

Change-Id: If257b16ee34d07820ae7ebdb9a3a598a41df013c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2202845
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-06-10 17:08:55 +00:00
Zach Reizner
73665866a0 msg_socket: remove MsgOnSocket impl for RawFd, an alias for i32
This implementation makes it impossible to use i32 as ordinary data in a
MsgOnSocket implementation. It is also error prone because i32 is the
default type for integer literals in Rust, and #[derive(MsgOnSocket)] on
structs with an i32 would suddenly be transmitting a RawFd.

This change also replaces the uses of RawFd's MsgOnSocket impl for one
based on File.

TEST=cargo build
BUG=None

Change-Id: I9da392e34e62fe61f773f24d656dbcbf4716f1a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197777
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-05-16 02:19:37 +00:00
Tomasz Jeznach
da0e0f939b devices: pci: refactor PCI devices to use PciAddress.
Simple refactor of PCI device addressing to use
PciAddress type providing bus:device.function number.

BUG=None
TEST=build_test & tast run crostini.Sanity

Change-Id: I7755ad6b31aa8c882475cd8212630e1cc86ef49e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2172766
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Tomasz Jeznach <tjeznach@chromium.org>
2020-05-01 05:49:39 +00:00
Chirantan Ekbote
2d9dde9ee7 Stop tracking sub-mappings in MemoryMappingArena
The kernel already takes care of tracking all our memory mappings.
Doing it again ourselves doesn't provide any benefit and also adds
additional restrictions (like not being able to overlap with existing
mappings or partially remove mappings).  Additionally, the
`MemoryMappingArena` will already unmap the entire memory mapped region
so there is no need to individually unmap the sub-mappings.

The kernel's mmap api doesn't have these restrictions and as far as I
can tell there are no safety concerns with allowing this behavior so
just stop tracking the sub-mappings.

Safe use of MAP_FIXED only requires that the address is part of a
previously mmaped region so allow any MemoryMapping to be converted into
a MemoryMappedArena.

BUG=b:147341783
TEST=unit tests

Change-Id: Iaf944a971b8ba9333802aab73c1d184fe388af89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2162542
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2020-04-29 07:36:36 +00:00
Charles William Dick
ed22f6b611 crosvm balloon_stats command
In preparation for moving balloon sizing logic from crosvm to concierge,
expose a balloon_stats command in crosvm. This will allow concierge to
query the actual balloon size and available memory of VMs.

BUG=b:153134684
TEST=(chroot)$ tast run <DUT> arc.Boot.vm; (vm)$ crosvm balloon_stats
<pipe>; See stats are reported.

Change-Id: I1f544526ee728a085d842035754a0c17cf41ed3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2141752
Tested-by: Charles Dueck <cwd@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Charles Dueck <cwd@chromium.org>
2020-04-13 02:59:02 +00:00
Daniel Verkamp
e1980a9c36 devices: pmem: implement flush using msync()
Previously, writable pmem devices implemented the flush command using
fsync(); however, this does not guarantee synchronization of memory
mappings via mmap() to the file on disk.  What we actually need is
msync() on the pmem file mapping, but we don't have access to that
mapping in the pmem child process, and it isn't trivial to pass it along
since it is owned by the Vm object once it has been added as a
mmap_arena.

In order to call msync() on the mapping, add a new VmControl socket so
that the pmem device can request that the main process issues an msync()
on the MemoryMappingArena identified by its slot number.

BUG=chromium:1007535
TEST=mount filesystem on /dev/pmem0 and sync; verify msync in strace

Change-Id: Id0484757c422cf81d454fd54012a12dbcc1baaf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2044365
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-08 06:09:25 +00:00
Dylan Reid
252d5b3cf3 handle mmap of large offsets on 32 bit systems
While only 32 bits of address can be mapped, that 32 bits can be offset
by further than 32 bits in to a large file. As chirantan points out, the
try_mmap call was already casting the usize to u64 on all architectures.

Convert the usize offset in mmap to u64 and address users of the API as
well.

Change-Id: I67aed928ea521049fb51eb7aa61ea4de8b4d096c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2124879
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-05 21:32:17 +00:00
Zach Reizner
146450b456 msg_socket: support dynamically sized types
This change is a major shift in how the MsgOnSocket trait works to allow
`self` to be used to determine the result `msg_size()`. This is to
support data structures with `Vec` or other dynamically sized type.

TEST=./build_test
     cargo test -p msg_socket
     tast run <DUT> crostini.CopyPaste.*
BUG=None

Cq-Depend: chromium:2025907
Change-Id: Ibdb51b377b2a2a77892f6c75e1a9f30b2f8b0240
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2029930
Tested-by: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2020-04-05 15:10:47 +00:00
Charles William Dick
664cc3ca49 crosvm virtio balloon stats
Introduces the ability to request BalloonStats from a
BalloonControlCommand.

BUG=b:147334004
TEST=tast run <DUT> arc.Boot.vm, and the balance available changes based
on this.

Change-Id: I808c4024f8c644c9cc4e30cc455ceda5f477bff3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2061517
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Charles Dueck <cwd@chromium.org>
2020-03-31 05:59:32 +00:00
Gurchetan Singh
83fc5c49ba devices: gpu: complete resource V2 rebase
* Remove RESOURCE_V2_UNREF
* Add RESOURCE_MAP/RESOURCE_UNMAP to enable resources without guest
  storage that don't need to be mapped directly either

BUG=chromium:924405
TEST=compile and test

Change-Id: I10d6cd120d86131fa7ed8917ddad25cdb99ae50c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015587
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2020-03-23 20:37:12 +00:00
Zach Reizner
bc7728f69b vm_control: fix double-close on VmIrqRequest::AllocateOneMsi
The EventFd that wraps the MaybeOwnedFd will close the fd, but so will
MaybeOwnedFd, causing a double-close.

BUG=None
TEST=strace crosvm run

Change-Id: I277386cd20eaa1a8187274cc16084b1936355012
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2034026
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2020-02-06 21:56:39 +00:00
Xiong Zhang
85abeff27f vfio: Implement bar mappable
if device bar is mappable, map bar's gpa to hpa in EPT, guest vcpu
could access this bar directly through EPT without trapping. This
could improve performance.

vm.add_mmio_memory could help do this, here vfio_pci send
RegisterMmapMemory request through vm_control socket to do this.

BUG=chromium:992270
TEST=none

Change-Id: I3b4274372f7dcd32e18084d55f037b6fe45ed422
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581147
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-12-06 08:47:29 +00:00
Xiong Zhang
383b3b520a resource: Rename device memory to mmio
Since unified allocator is used to allocate mmio, this patch remove the
device memory name, and rename device to mmio.

BUG=chromium:992270
TEST=this patch doesn't change function, run build_test

Change-Id: I234b0db4b3c5de8cfee372ace5212a980564d0c7
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895234
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-10 06:39:34 +00:00
Xiong Zhang
87a3b44d9e Resource: Unify mmio allocator
Current mmio and device two allocators exist, the purpose to define
two allocator is:
Accessing to gpa from mmio allocator cause vm exit, while gpa from
device allocator doesn't cause vm exit.

Whether vm exits exist or not, dependency on whether
vm->add_device_memory() is called with gpa from allocator or not.Even
if gpa is from mmio alloator, and vm->add_device_memory() is called
with this gpa, accessing this gpa won't cause vm exit. So mmio allocator
and device allocator couldn't guarantee the original purpose.

This patch unify mmio allocator and device allocator into one mmio
allocator.

BUG=chromium:992270
TEST=this patch doesn't change function, so just run build_test

Change-Id: If87d5c2838eb122ef627fa45c394b1b3ccfafeb0
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1895233
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-11-10 06:39:31 +00:00
Daniel Verkamp
6494117e17 usb: replace libusb with Rust usb_util library
Drop the dependency on libusb and reimplement the host USB backend using
usb_sys to wrap the Linux usbdevfs ioctls.

This allows sandboxing to work without any dependency on libusb patches,
and it gives us the flexibility to modify and update the USB backend
without depending on an external third-party library.

BUG=chromium:987833
TEST=`adb logcat` on nami with Nexus 5 attached
TEST=deploy app to phone with Android Studio
TEST=Run EdgeTPU USB accelerator demo (including DFU mode transition)

Cq-Depend: chromium:1773695
Change-Id: I4321c2b6142caac15f48f197795a37d59d268831
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1783601
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-17 00:20:24 +00:00
Xiong Zhang
2515b75630 vm_control: Add VmIrqRequest Socket
When vfio device's msi/msi-x or virtio device's msi-x is enabled,
its irq routing info should be notified to kvm. But this is a runtime
vm service call, so vm_control is used to call vm service.

VmIrqRequest->AllocateOneMsi() is used to allocate one gsi for a msi
and a msi-x vector, and link gsi with irqfd through vm->register_irqfd.
The orignal interrupt_evt and interrupt_resample_interrupt is used for
INTX only.

VmIrqRequest->AddMsiRoute is used to add msi routing info into kvm
route table.

BUG=chromium:992270
TEST=none

Change-Id: I4f1beeb791943e09d957573dd2a58d55bf895d16
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1846603
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Xiong  Zhang <xiong.y.zhang@intel.corp-partner.google.com>
2019-10-15 11:41:38 +00:00
Gurchetan Singh
7ca5e3dba3 vm_control: support registering memory at a specific address
The guest kernel will allocate from PCI range of the virtgpu
device, and send physical addresses via a hypercall.

Right now, only support buffers that can be mmap'ed.  We could
add optimizations for GBM buffers later if needed.

BUG=chromium:924405
TEST=compile

Change-Id: I094de96a2c35bcd2e18c8a6a2d8cdc39bb392e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1626794
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-10-01 07:53:32 +00:00
Daniel Verkamp
a445ae1fbe Remove remaining byteorder crate references
Remove the last (unused) reference to byteorder in vm_control/Cargo.toml
and remove it from the list of external crates in README.md.

BUG=None
TEST=./build_test

Change-Id: Ie70c0bc2f96c19b34ef1596885245eca7bc202f4
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761156
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-08-26 23:41:54 +00:00
Gurchetan Singh
53edb817da crosvm: {WlDriverRequest, WlDriverResponse} --> {VmMemoryRequest, VmMemoryResponse}
These type of requests are not necessarily specific to the virtio-wl,
and other devices (virtio-gpu) may want to use them.

BUG=chromium:924405
TEST=compile

Change-Id: Iad0889da8ab3d23bb2378448fc05e3c840a93d93
Reviewed-on: https://chromium-review.googlesource.com/1626791
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-05-24 15:09:26 -07:00
Zach Reizner
aff94ca6da usb: support for listing attached usb devices
Originally, crosvm would list details about an attached usb device for a
given port. This change allows getting details about multiple ports at
once. This is intended to simplify command line usage and downstream
consumers like concierge.

TEST=various vmc commands
     Chrome UI for handling USB devices
BUG=chromium:831850

Change-Id: I55681a7fea7425c897a22a579dcc15567683ef54
Reviewed-on: https://chromium-review.googlesource.com/1529765
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-27 01:36:47 -07:00
Jakub Staron
d99cd0ae0b crosvm: Extracts Wayland commands from from VmRequest.
BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: I07f034b1cc41e30b9deae68ea9c510b0923e17a8
Reviewed-on: https://chromium-review.googlesource.com/1565299
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-27 01:36:38 -07:00
Jakub Staron
1f828d7cd7 Extracts BalloonAdjust from VmRequest.
Extracts BalloonAdjust from VmRequest into BalloonControlCommand.

BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: Ia9f5778c37c8fd4fa560df413134d1b441142f64
Reviewed-on: https://chromium-review.googlesource.com/1565298
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-04-25 00:59:51 -07:00
Daniel Prilik
d92f81a249 resources+pci: allocator rework (allocation tags)
AddressAllocator now maintains a HashMap<Alloc, (u64, u64, u64)>,
which uniquely maps a Allocation enum (e.g: PciBar(bus, dev, bar),
GpuRenderNode, etc...) to it's address, size, and human-readable tag
/ description.

The interface has also been modified to use Error instead of Option.

Aside from improving debugging, tracking allocations will have
numerous uses in the future. For example, when allocating guest memory
over VmControl sockets, it will be possible to restrict allocations to
pre-allocated slices of memory owned by the requesting device.

To plumb through PCI information to PCI devices, this CL necessitated
the addition of a PciDevice method called `assign_bus_dev`, which
notifies PCI devices of their uniquely assigned Bus and Device numbers.

BUG=chromium:936567
TEST=cargo test -p resources && cargo build --features="gpu gpu-forward"

Change-Id: I8b4b0e32c6f3168138739249ede53d03143ee5c3
Reviewed-on: https://chromium-review.googlesource.com/1536207
Commit-Ready: Daniel Prilik <prilik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-20 03:58:40 -07:00
Jakub Staron
ecf81e0f05 Extracts DiskResize from VmRequest to a new type.
BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: Icf26f53d3fd813ab43b8f14079f90628d245eed7
Reviewed-on: https://chromium-review.googlesource.com/1565297
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-19 14:45:21 -07:00
Jakub Staron
8c35fc361b Removes RegisterIoevent and RegisterIrqfd.
Removes unused RegisterIoevent and RegisterIrqfd variants from
VmRequest.

BUG=None
TEST=cargo check
TEST=cargo test
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: I3b4ced415b0f4a8e7969ddc149f82082593a8e8c
Reviewed-on: https://chromium-review.googlesource.com/1565296
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-17 17:23:10 -07:00
David Tolnay
2b82fbbeda clippy: Resolve unneeded_field_pattern
TEST=bin/clippy

Change-Id: Ia0e0163441fafd4ce44fef7ebaa18d1cc947e20e
Reviewed-on: https://chromium-review.googlesource.com/1566891
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:55 -07:00
David Tolnay
9239602d69 clippy: Resolve needless_return
TEST=bin/clippy

Change-Id: I62eb3f86b01a6000107c54a967689d4e430adf50
Reviewed-on: https://chromium-review.googlesource.com/1566743
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-17 17:22:52 -07:00
David Tolnay
aecf9a4dee edition: Remove extern crate lines
In Rust 2018 edition, `extern crate` is no longer required for importing
from other crates. Instead of writing:

    extern crate dep;
    use dep::Thing;

we write:

    use dep::Thing;

In this approach, macros are imported individually from the declaring
crate rather than through #[macro_use]. Before:

    #[macro_use]
    extern crate sys_util;

After:

    use sys_util::{debug, error};

The only place that `extern crate` continues to be required is in
importing the compiler's proc_macro API into a procedural macro crate.
This will hopefully be fixed in a future Rust release.

    extern crate proc_macro;

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=local kokoro

Change-Id: I0b43768c0d81f2a250b1959fb97ba35cbac56293
Reviewed-on: https://chromium-review.googlesource.com/1565302
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:08 -07:00
David Tolnay
633426a8fc edition: Fill in macro imports
Macros were previously imported through `#[macro_use] extern crate`,
which is basically a glob import of all macros from the crate. As of
2018 edition of Rust, `extern crate` is no longer required and macros
are imported individually like any other item from a dependency. This CL
fills in all the appropriate macro imports that will allow us to remove
our use of `extern crate` in a subsequent CL.

TEST=cargo check --all-features --tests
TEST=kokoro

Change-Id: If2ec08b06b743abf5f62677c6a9927c3d5d90a54
Reviewed-on: https://chromium-review.googlesource.com/1565546
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:07 -07:00
Jakub Staron
e7c590507c Wrap the UnixSeqpacket with a more descriptive type.
Host/device sockets are now created as a pairs of MsgSockets instead of UnixSeqpacket sockets.

BUG=chromium:950663
TEST=cargo check
TEST=cargo test

Change-Id: I8f61a711fe3c2547bf5d18fcfa23bfd0dc0ef5fd
Reviewed-on: https://chromium-review.googlesource.com/1559041
Commit-Ready: Jakub Staroń <jstaron@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Jakub Staroń <jstaron@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-04-10 02:20:58 -07:00
David Tolnay
48ff4165d2 cargo: Sort all dependency lists in Cargo.toml
This may help reduce cases of conflicts between independent CLs each
appending a dependency at the bottom of the list, of which I hit two
today rebasing some of my open CLs.

TEST=cargo check --all-features

Change-Id: Ief10bb004cc7b44b107dc3841ce36c6b23632aed
Reviewed-on: https://chromium-review.googlesource.com/1557172
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-09 01:55:14 -07:00
David Tolnay
fdac5ede46 edition: Use dyn syntax for trait objects
Found by running: `cargo rustc -- -D bare_trait_objects`

Bare trait objects like `&Trait` and `Box<Trait>` are soft-deprecated in
2018 edition and will start warning at some point.

As part of this, I replaced `Box<Trait + 'static>` with `Box<dyn Trait>`
because the 'static bound is implied for boxed trait objects.

TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=local kokoro

Change-Id: I41c4f13530bece8a34a8ed1c1afd7035b8f86f19
Reviewed-on: https://chromium-review.googlesource.com/1513059
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-08 02:51:37 -07:00
David Tolnay
4a0fa14059 edition: Update vm_control to 2018 edition
Separated out of CL:1513058 to make it possible to land parts
individually while the affected crate has no other significant CLs
pending. This avoids repeatedly introducing non-textual conflicts with
new code that adds `use` statements.

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: Iedc030e90e4c4e11cf69dde711df24caafc0ea4c
Reviewed-on: https://chromium-review.googlesource.com/1520074
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-08 02:51:35 -07:00
Jingkui Wang
100e6e48ad implement xhci and add it to pci bus
Implement xhci controller, setup seccomp filters and add xhci to pci
bus.

CQ-DEPEND=CL:1512761
BUG=chromium:831850
TEST=local build
Change-Id: I5c05452ece66e99d3a670e259e095fca616e835d
Reviewed-on: https://chromium-review.googlesource.com/1512762
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2019-03-17 21:33:08 -07:00
Jingkui Wang
257d004b0c usb: add host backend
Host backend implement backend device. It will attach a read device to
xhci controller.

Also squashed from ce6b35, author: zachr@.

CQ-DEPEND=CL:1510820
BUG=chromium:831850
TEST=local build

Change-Id: Idcf2d7d6aca92de9859b7c38d1bf1d98032eae91
Reviewed-on: https://chromium-review.googlesource.com/1512761
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-03-16 15:25:23 -07:00
Zach Reizner
7898632b42 main: log responses to command line vm control requests
Now that the connection oriented seqpacket sockets are used for vm
control messages, a response can be received by the requested. This
change prints out that response.

TEST=crosvm suspend|resume|balloon|stop <socket>
BUG=chromium:848187

Change-Id: I18ac23c26127332e2be498113cc0c3310fd09a7d
Reviewed-on: https://chromium-review.googlesource.com/1482370
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-02-28 03:24:25 -08:00
Zach Reizner
a60744b42e crosvm: use seqpacket rather than datagram sockets
The advantage of seqpacket is that they are connection oriented. A
listener can be created that accepts new connections, useful for the
path based VM control sockets. Previously, the only bidirectional
sockets in crosvm were either stream based or made using socketpair.

This change also whitelists sendmsg and recvmsg for the common device
policy.

TEST=cargo test
BUG=chromium:848187

Change-Id: I83fd46f54bce105a7730632cd013b5e7047db22b
Reviewed-on: https://chromium-review.googlesource.com/1470917
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-02-28 03:24:24 -08:00
David Tolnay
b4bd00fdad error: Print errors using Display impl
I have been running into Debug-printed error messages too often and
needing to look up in the source code each level of nested errors to
find out from the comment on the error variant what the short name of
the variant means in human terms. Worse, many errors (like the one shown
below) already had error strings written but were being printed from the
calling code in the less helpful Debug representation anyway.

Before:
    [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty

After:
    [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices.

TEST=cargo check --all-features
TEST=FEATURES=test emerge-amd64-generic crosvm

Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10
Reviewed-on: https://chromium-review.googlesource.com/1469225
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-02-20 08:20:02 -08:00
Zach Reizner
6a8fdd9f8e crosvm: add suspend/resume commands
This change adds the suspend and resume commands to crosvm, as well as
corresponding VmRequest variants and VCPU loop support. When a request
triggers a VmRunMode change, the Mutex guarded shared VmRunMode variable
is mutated and the associated Condvar is notified. Each VCPU thread is
interrupted to kick it out of the KVM_RUN call and checks the VmRunMode,
If the VCPU was already suspended by waiting for the Condvar, the
notify_all call will wake up the thread, upon which the VCPU thread can
respond to the new mode.

TEST=crosvm suspend/crosvm resume
BUG=chromium:920875

Change-Id: Ibbeb748ab0d64402c7196890815e8e1cb4dfca38
Reviewed-on: https://chromium-review.googlesource.com/1416317
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-01-23 20:40:38 -08:00
Daniel Verkamp
92f73d73d0 devices: block: add resize VmControl request
This allows manual resizing of block devices at runtime via the command
line ('crosvm disk resize <index> <size>').  The virtio config interrupt
is asserted when the disk size changes so that the guest driver can
update the block device to the updated size.

Currently, there is no automatic policy for resizing disks - that will
be implemented in another change.  Additionally, this resize operation
just changes the size of the block device; the filesystem will need to
be resized by the guest (e.g. via the 'btrfs filesystem resize' command)
as a separate step either before (shrinking) or after (expanding) the
disk resize operation.

BUG=chromium:858815
TEST=Start crosvm with a control socket (-s) and resize the disk with
'crosvm disk resize' from another shell.

Change-Id: I01633a7af04bfbaffbd27b9227274406d2a2b9cb
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1394152
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-01-16 01:46:54 -08:00
Daniel Verkamp
f76869d2a6 devices: balloon: fix the 'crosvm balloon' command
The balloon socket interface was changed to take an absolute number of
pages in a u64 in commit 448516e3f9 ("balloon: Implement device
policy"), but the 'crosvm balloon' command wasn't updated to match.  Fix
the crosvm front-end to send a u64 as expected by the command socket
reader instead of the i32 it was sending previously, and change the
parameter to bytes instead of pages to match the receiving end as well.

BUG=None
TEST=crosvm balloon a running VM to various sizes

Change-Id: I265bee55c06809de7559a79a5eb6d0d094533993
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1394157
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2019-01-05 20:08:41 -08:00
David Tolnay
5bbbf61082 lint: Resolve the easier clippy lints
Hopefully the changes are self-explanatory and uncontroversial. This
eliminates much of the noise from `cargo clippy` and, for my purposes,
gives me a reasonable way to use it as a tool when writing and reviewing
code.

Here is the Clippy invocation I was using:

    cargo +nightly clippy -- -W clippy::correctness -A renamed_and_removed_lints -Aclippy::{blacklisted_name,borrowed_box,cast_lossless,cast_ptr_alignment,enum_variant_names,identity_op,if_same_then_else,mut_from_ref,needless_pass_by_value,new_without_default,new_without_default_derive,or_fun_call,ptr_arg,should_implement_trait,single_match,too_many_arguments,trivially_copy_pass_by_ref,unreadable_literal,unsafe_vector_initialization,useless_transmute}

TEST=cargo check --features wl-dmabuf,gpu,usb-emulation
TEST=boot linux

Change-Id: I55eb1b4a72beb2f762480e3333a921909314a0a2
Reviewed-on: https://chromium-review.googlesource.com/1356911
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-12-03 20:32:03 -08:00
Jingkui Wang
e13b180f74 crosvm: use msg_socket in vm_control
Refactor existing code to use msg_socket.

BUG=None
TEST=local build and run

Change-Id: Iee72326b330e035303f679e1aedd6e5d18ad4f8a
Reviewed-on: https://chromium-review.googlesource.com/1260260
Commit-Ready: Jingkui Wang <jkwang@google.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-11-19 16:28:35 -08:00
Daniel Verkamp
db6edff22f kvm: refactor ioeventfd datamatch interface
This allows the caller to specify the full range of datamatch options
defined in the KVM ioeventfd API, including matching accesses of a
particular size with or without matching a specific data value.

BUG=None
TEST=cargo test -p kvm

Change-Id: I28b543f7c0b35eb2a6d47a14a33145ea00d09d1d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1271836
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-11 13:25:38 -07:00
Zach Reizner
55a9e504be cargo fmt all source code
Now that cargo fmt has landed, run it over everything at once to bring
rust source to the standard formatting.

TEST=cargo test
BUG=None

Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b
Reviewed-on: https://chromium-review.googlesource.com/1259287
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-09 21:14:05 -07:00
Zach Reizner
a99954cb7c sys_util: remove Scm struct and sock_ctrl_msg C library
The Scm object was made to reduce the number of heap allocations in
the hot paths of poll loops, at the cost of some code complexity. As it
turns out, the number of file descriptors being sent or received is
usually just one or limited to a fixed amount that can easily be covered
with a fixed size stack allocated buffer.

This change implements that solution, with heap allocation as a backup
in the rare case that many file descriptors must be sent or received.

This change also moves the msg and cmsg manipulation code out of C and
into pure Rust. The move was necessary to allocate the correct amount
of buffer space at compile time. It also improves safety by reducing the
scope of unsafe code. Deleting the code for building the C library is
also a nice bonus.

Finally, the removal of the commonly used Scm struct required
transitioning existing usage to the ScmSocket trait based methods. This
includes all those changes.

TEST=cargo test
BUG=None

Change-Id: If27ba297f5416dd9b8bc686ce740866912fa0aa0
Reviewed-on: https://chromium-review.googlesource.com/1186146
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-09-17 21:34:50 -07:00
Dylan Reid
228e4a6a91 Move gpu allocator to resources
Combine GPU buffer allocation with the system resource allocator making
life easier as only one allocator needs to get passed to the execute
function.

Change-Id: I199eb0fd6b99b629aaec1ae3295e8a1942da5309
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1099856
2018-07-09 17:59:23 -07:00
Dylan Reid
ef7352f208 Remove the device manager and use the new resource allocator
Allow IRQs to be assigned before creating device manager.

For PCI, we need to add devices with interrupts before MMIO setup. Add
the ability to tell the architecture device manager about IRQs that we
have stolen.

There was only one function in device_manager and all of its state is
now delegated to the resource allocator, remove it.

Change-Id: I9afa0e3081a20cb024551ef18ae34fe76a1ef39d
Reviewed-on: https://chromium-review.googlesource.com/1089720
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
2018-06-29 17:50:17 -07:00
David Reveman
5f5e7ec3ba virtwl: better multi-plane DMABuf support
Multi-plane DMABufs are useful for efficient video playback. The
guest can already use this but has to guess the stride and offsets
for the second and third plane as they are not passed by virtwl
to the guest kernel.

This extracts the correct strides and offsets for each buffer and
passes them back to the guest in the allocation response message.

BUG=chromium:837209
TEST=sommelier can use nv12 buffers without guessing stride/offset

Change-Id: I36ae2fad6605293c907802121676296cbc607a57
Reviewed-on: https://chromium-review.googlesource.com/1070799
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-26 10:19:50 -07:00
David Reveman
52ba4e5c64 virtwl: Add DMABuf allocation support.
This implements DMABuf allocation type in the virtio wayland
device.

We attempt to locate a supported DRM device prior to engaging
the device jail. If found, the DRM device is passed to the
wayland device code and used to serve DMABuf allocations.

DMABuf support can be disabled by not providing crosvm with
access to any DRM device nodes.

The guest is expected to handle the case when DMABuf allocation
fails and fall-back to standard shared memory.

This initial change uses DRM directly but is structured in a
way that would allow the allocator to be replaced by minigbm
with minimal effort.

BUG=chromium:837209
TEST=crosvm finds drm device and returns valid dmabufs to guest

Change-Id: Ic1fd776dfdfefae2d7b321d449273ef269e9cc62
Reviewed-on: https://chromium-review.googlesource.com/1034088
Commit-Ready: David Reveman <reveman@chromium.org>
Tested-by: David Reveman <reveman@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-05-16 08:34:40 -07:00
Dmitry Torokhov
505c6f9888 vm_control: more error signedness fixes
Fix a couple more spaces where we used negative errno values.

TEST=cargo test -p vm_control
BUG=None

Change-Id: Id622192d025d0ac733419411492ca53a50f957f3
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/942087
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-03-01 16:13:07 -08:00
Dmitry Torokhov
8283248a60 vm_control: do not use negative error coded for errno-based errors
Errors derived from sysem errors delivered via -1 return code/errno
should use positive error codes, not negative, in order for them to be
recognized by other components. I.e. we should use
errno::Error::new(EINVAL) and not -EINVAL.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=None

Change-Id: I10d5992cb1e1750aa9b8a7269c4f574d7c753683
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939866
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-27 20:17:07 -08:00
Zach Reizner
e0e8e56732 kvm: support adding read only memory to VMs
Read only memory is useful for triggering VM exits when the VM writes to
memory while allowing reads transparently and quickly. For example, a
virtual device implementation might not care if the VM reads a memory
mapped device register, but a exit would be required if the VM wrote to
the same register.

TEST=cargo test -p kvm; ./build_test
BUG=chromium:800626

Change-Id: Ic605b2cfc2a1e44941d91945f9390b9abb820040
Reviewed-on: https://chromium-review.googlesource.com/903075
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-02-06 21:32:39 -08:00
Sonny Rao
29cd40a1d6 crosvm: change GuestAddress to always be a u64
We want to be able to run 64-bit ARM kernels using a 32-bit version of
crosvm, to make it more consistent use a u64 to represent
GuestAddress.

BUG=chromium:797868
TEST=./build_test passes on all architectures
TEST=crosvm runs on caroline

Change-Id: I43bf993592caf46891e3e5e05258ab70b6bf3045
Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/896398
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2018-02-01 18:08:55 -08:00
Zach Reizner
855ac29cf2 kvm: add dirty log support
This add safe support for KVM's KVM_GET_DIRTY_LOG ioctl.

TEST=./build_test
BUG=None

Change-Id: I3d0f996927844a33addd072f2bfc62361f8b7fe0
Reviewed-on: https://chromium-review.googlesource.com/848019
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-01-03 16:54:34 -08:00
Dylan Reid
d44320488f main: Add inflate/deflate interface for balloon
Change-Id: I0fc63abbed8db303c7d283ce392fd47777b60d19
Reviewed-on: https://chromium-review.googlesource.com/818207
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-01-02 23:36:26 -08:00
Dylan Reid
f31455e966 sys_util/vm_control: Don't test shm if memfd_create doesn't exist
On older kernels, the memfd_create syscall isn't available. Skip shm
tests if that is the case.

Change-Id: I39c1f1779f1f02e90df727c6ca18b5bdae52e855
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/768102
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2017-11-16 21:07:43 -08:00
Dylan Reid
94bf1bf6b4 Move vm_control to a top-level crate
Break out vm_control to a crate that will be able to used by more
modules. Having vm_control usable from outside crosvm makes it possible
to move the devices out of crosvm in a later commit.

Change-Id: I1f060700ed49b5d77519d55efa2430490d521256
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/706558
Reviewed-by: Zach Reizner <zachr@chromium.org>
2017-10-09 17:39:04 -07:00