mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Refactor VM creation workflow
This refactoring is required to add support for creating SEV-SNP enabled VM. Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
5fd79571b7
commit
200cba0e20
@@ -1312,6 +1312,8 @@ impl Vmm {
|
||||
&self.hypervisor,
|
||||
#[cfg(feature = "tdx")]
|
||||
false,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
false,
|
||||
)
|
||||
.map_err(|e| {
|
||||
MigratableError::MigrateReceive(anyhow!(
|
||||
|
||||
@@ -759,10 +759,19 @@ impl Vm {
|
||||
vm_config.lock().unwrap().is_tdx_enabled()
|
||||
};
|
||||
|
||||
#[cfg(feature = "sev_snp")]
|
||||
let sev_snp_enabled = if snapshot.is_some() {
|
||||
false
|
||||
} else {
|
||||
vm_config.lock().unwrap().is_sev_snp_enabled()
|
||||
};
|
||||
|
||||
let vm = Self::create_hypervisor_vm(
|
||||
&hypervisor,
|
||||
#[cfg(feature = "tdx")]
|
||||
tdx_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
sev_snp_enabled,
|
||||
)?;
|
||||
|
||||
let phys_bits = physical_bits(&hypervisor, vm_config.lock().unwrap().cpus.max_phys_bits);
|
||||
@@ -821,17 +830,31 @@ impl Vm {
|
||||
pub fn create_hypervisor_vm(
|
||||
hypervisor: &Arc<dyn hypervisor::Hypervisor>,
|
||||
#[cfg(feature = "tdx")] tdx_enabled: bool,
|
||||
#[cfg(feature = "sev_snp")] sev_snp_enabled: bool,
|
||||
) -> Result<Arc<dyn hypervisor::Vm>> {
|
||||
hypervisor.check_required_extensions().unwrap();
|
||||
|
||||
// 0 for KVM_X86_LEGACY_VM
|
||||
// 1 for KVM_X86_TDX_VM
|
||||
#[cfg(feature = "tdx")]
|
||||
let vm = hypervisor
|
||||
.create_vm_with_type(u64::from(tdx_enabled))
|
||||
.unwrap();
|
||||
#[cfg(not(feature = "tdx"))]
|
||||
let vm = hypervisor.create_vm().unwrap();
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "tdx")] {
|
||||
let vm = hypervisor
|
||||
.create_vm_with_type(if tdx_enabled {
|
||||
1 // KVM_X86_TDX_VM
|
||||
} else {
|
||||
0 // KVM_X86_LEGACY_VM
|
||||
})
|
||||
.unwrap();
|
||||
} else if #[cfg(feature = "sev_snp")] {
|
||||
let vm = hypervisor
|
||||
.create_vm_with_type(if sev_snp_enabled {
|
||||
1 // SEV_SNP_ENABLED
|
||||
} else {
|
||||
0 // SEV_SNP_DISABLED
|
||||
})
|
||||
.unwrap();
|
||||
} else {
|
||||
let vm = hypervisor.create_vm().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user