Skip to content

Commit

Permalink
devices: Add pvmemcontrol device
Browse files Browse the repository at this point in the history
Pvmemcontrol provides a way for the guest to control its physical memory
properties, and enables optimizations and security features. For
example, the guest can provide information to the host where parts of a
hugepage may be unbacked, or sensitive data may not be swapped out, etc.

Pvmemcontrol allows guests to manipulate its gPTE entries in the SLAT,
and also some other properties of the memory map the back's host memory.
This is achieved by using the KVM_CAP_SYNC_MMU capability. When this
capability is available, the changes in the backing of the memory region
on the host are automatically reflected into the guest. For example, an
mmap() or madvise() that affects the region will be made visible
immediately.

There are two components of the implementation: the guest Linux driver
and Virtual Machine Monitor (VMM) device. A guest-allocated shared
buffer is negotiated per-cpu through a few PCI MMIO registers, the VMM
device assigns a unique command for each per-cpu buffer. The guest
writes its pvmemcontrol request in the per-cpu buffer, then writes the
corresponding command into the command register, calling into the VMM
device to perform the pvmemcontrol request.

The synchronous per-cpu shared buffer approach avoids the kick and busy
waiting that the guest would have to do with virtio virtqueue transport.

The Cloud Hypervisor component can be enabled with --pvmemcontrol.

A proof of concept program using the userspace interface to send
MADV_DONTNEED for a hugetlb page on the host can be found at:
https://github.com/Dummyc0m/pvmemcontrol-user

Signed-off-by: Yuanchu Xie <yuanchu@google.com>
  • Loading branch information
yuanchu-xie committed Jun 7, 2024
1 parent 87f1d08 commit 6b4c78f
Show file tree
Hide file tree
Showing 11 changed files with 1,005 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion devices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ event_monitor = { path = "../event_monitor" }
hypervisor = { path = "../hypervisor" }
libc = "0.2.153"
log = "0.4.21"
num_enum = "0.7.2"
pci = { path = "../pci" }
serde = { version = "1.0.197", features = ["derive"] }
thiserror = "1.0.60"
tpm = { path = "../tpm" }
vm-allocator = { path = "../vm-allocator" }
vm-device = { path = "../vm-device" }
vm-memory = "0.14.1"
vm-memory = { version = "0.14.1", features = [
"backend-mmap",
"backend-atomic",
"backend-bitmap",
] }
vm-migration = { path = "../vm-migration" }
vmm-sys-util = "0.12.1"

Expand Down
1 change: 1 addition & 0 deletions devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod interrupt_controller;
#[cfg(target_arch = "x86_64")]
pub mod ioapic;
pub mod legacy;
pub mod pvmemcontrol;
pub mod pvpanic;
pub mod tpm;

Expand Down
Loading

0 comments on commit 6b4c78f

Please sign in to comment.