Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/hyperlight_host/src/hypervisor/hypervisor_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ impl HypervisorHandler {
e
)
})?;
// This apparently-useless lock is
// needed to ensure the host does not
// make unsynchronized accesses while
// the guest is executing. See the
// documentation for
// GuestSharedMemory::lock.
let mem_lock_guard = evar_lock_guard
.as_mut()
.ok_or_else(|| {
Expand Down Expand Up @@ -399,6 +405,12 @@ impl HypervisorHandler {
e
)
})?;
// This apparently-useless lock is
// needed to ensure the host does not
// make unsynchronized accesses while
// the guest is executing. See the
// documentation for
// GuestSharedMemory::lock.
let mem_lock_guard = evar_lock_guard
.as_mut()
.ok_or_else(|| {
Expand Down
9 changes: 9 additions & 0 deletions src/hyperlight_host/src/mem/shared_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ unsafe impl Send for ExclusiveSharedMemory {}
pub struct GuestSharedMemory {
region: Arc<HostMapping>,
/// The lock that indicates this shared memory is being used by non-Rust code
///
/// This lock _must_ be held whenever the guest is executing,
/// because it prevents the host from converting its
/// HostSharedMemory to an ExclusiveSharedMemory. Since the guest
/// may arbitrarily mutate the shared memory, only synchronized
/// accesses from Rust should be allowed!
///
/// We cannot enforce this in the type system, because the memory
/// is mapped in to the VM at VM creation time.
pub lock: Arc<RwLock<()>>,
}
unsafe impl Send for GuestSharedMemory {}
Expand Down
Loading