Skip to content

Commit 106244d

Browse files
kalyazinroypat
authored andcommitted
chore(vmm): prohibit restoring from a file if secret free
In a regular VM, we mmap the memory snapshot file and supply the address in the KVM memory slot. In Secret Free VMs, we provide guest_memfd in the memory slot instead. There is no way we can restore a Secret Free VM from a file, unless we prepopulate the guest_memfd with the file content, which is inefficient and is not practically useful. Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent d94cfd7 commit 106244d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/vmm/src/persist.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::utils::u64_to_usize;
3434
use crate::vmm_config::boot_source::BootSourceConfig;
3535
use crate::vmm_config::instance_info::InstanceInfo;
3636
use crate::vmm_config::machine_config::{HugePageConfig, MachineConfigError, MachineConfigUpdate};
37-
use crate::vmm_config::snapshot::{CreateSnapshotParams, LoadSnapshotParams};
37+
use crate::vmm_config::snapshot::{CreateSnapshotParams, LoadSnapshotParams, MemBackendType};
3838
use crate::vstate::kvm::KvmState;
3939
use crate::vstate::memory;
4040
use crate::vstate::memory::{GuestMemoryState, GuestRegionMmap, MemoryError};
@@ -371,6 +371,17 @@ pub fn restore_from_snapshot(
371371
vm_resources: &mut VmResources,
372372
) -> Result<Arc<Mutex<Vmm>>, RestoreFromSnapshotError> {
373373
let mut microvm_state = snapshot_state_from_file(&params.snapshot_path)?;
374+
375+
if microvm_state.vm_info.secret_free && params.mem_backend.backend_type == MemBackendType::File
376+
{
377+
return Err(RestoreFromSnapshotError::Build(
378+
BuildMicrovmFromSnapshotError::VmUpdateConfig(MachineConfigError::Incompatible(
379+
"secret freedom",
380+
"file memory backend",
381+
)),
382+
));
383+
}
384+
374385
for entry in &params.network_overrides {
375386
microvm_state
376387
.device_states

0 commit comments

Comments
 (0)