mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: hypervisor: simplify VM creation API
For MSHV customers don't want to make everything default during partition creation. For example nested support, some synthetic features could be controlled from CLI through platform argument. Create_vm API getting messy after adding more flags. This patch introduces common data struct to be passed from vmm crate to hypervisor crate during partition creation. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
+21
-11
@@ -2861,14 +2861,16 @@ mod tests {
|
||||
use arch::layout::{BOOT_STACK_POINTER, ZERO_PAGE_START};
|
||||
use arch::x86_64::interrupts::*;
|
||||
use arch::x86_64::regs::*;
|
||||
use hypervisor::StandardRegisters;
|
||||
use hypervisor::arch::x86::{FpuState, LapicState};
|
||||
use hypervisor::{HypervisorVmConfig, StandardRegisters};
|
||||
use linux_loader::loader::bootparam::setup_header;
|
||||
|
||||
#[test]
|
||||
fn test_setlint() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||
let vm = hv
|
||||
.create_vm(HypervisorVmConfig::default())
|
||||
.expect("new VM fd creation failed");
|
||||
hv.check_required_extensions().unwrap();
|
||||
// Calling get_lapic will fail if there is no irqchip before hand.
|
||||
vm.create_irq_chip().unwrap();
|
||||
@@ -2894,7 +2896,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_setup_fpu() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||
let vm = hv
|
||||
.create_vm(HypervisorVmConfig::default())
|
||||
.expect("new VM fd creation failed");
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
setup_fpu(&vcpu).unwrap();
|
||||
|
||||
@@ -2918,7 +2922,9 @@ mod tests {
|
||||
use hypervisor::arch::x86::{MsrEntry, msr_index};
|
||||
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||
let vm = hv
|
||||
.create_vm(HypervisorVmConfig::default())
|
||||
.expect("new VM fd creation failed");
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
setup_msrs(&vcpu).unwrap();
|
||||
|
||||
@@ -2944,7 +2950,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_setup_regs_for_pvh() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||
let vm = hv
|
||||
.create_vm(HypervisorVmConfig::default())
|
||||
.expect("new VM fd creation failed");
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
|
||||
let mut expected_regs: StandardRegisters = vcpu.create_standard_regs();
|
||||
@@ -2968,7 +2976,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_setup_regs_for_bzimage() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||
let vm = hv
|
||||
.create_vm(HypervisorVmConfig::default())
|
||||
.expect("new VM fd creation failed");
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
|
||||
let mut expected_regs: StandardRegisters = vcpu.create_standard_regs();
|
||||
@@ -3000,7 +3010,6 @@ mod tests {
|
||||
use std::{mem, mem::offset_of};
|
||||
|
||||
use arch::layout;
|
||||
use hypervisor::HypervisorCpuError;
|
||||
use hypervisor::arch::aarch64::regs::MPIDR_EL1;
|
||||
#[cfg(feature = "kvm")]
|
||||
use hypervisor::arm64_core_reg_id;
|
||||
@@ -3010,11 +3019,12 @@ mod tests {
|
||||
use hypervisor::kvm::kvm_bindings::{
|
||||
KVM_REG_ARM_CORE, KVM_REG_ARM64, KVM_REG_ARM64_SYSREG, KVM_REG_SIZE_U64, user_pt_regs,
|
||||
};
|
||||
use hypervisor::{HypervisorCpuError, HypervisorVmConfig};
|
||||
|
||||
#[test]
|
||||
fn test_setup_regs() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
|
||||
// Must fail when vcpu is not initialized yet.
|
||||
@@ -3030,7 +3040,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_read_mpidr() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
let mut kvi = vcpu.create_vcpu_init();
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
@@ -3055,7 +3065,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_save_restore_core_regs() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
let mut kvi = vcpu.create_vcpu_init();
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
@@ -3105,7 +3115,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_set_mpstate() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
let mut kvi = vcpu.create_vcpu_init();
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
|
||||
+14
-22
@@ -45,7 +45,7 @@ use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs;
|
||||
use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use hypervisor::arch::aarch64::regs::AARCH64_PMU_IRQ;
|
||||
use hypervisor::{HypervisorVmError, VmOps};
|
||||
use hypervisor::{HypervisorVmConfig, HypervisorVmError, VmOps};
|
||||
use libc::{SIGWINCH, termios};
|
||||
use linux_loader::cmdline::Cmdline;
|
||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
||||
@@ -1084,26 +1084,16 @@ impl Vm {
|
||||
#[cfg(feature = "sev_snp")] mem_size: u64,
|
||||
) -> Result<Arc<dyn hypervisor::Vm>> {
|
||||
hypervisor.check_required_extensions().unwrap();
|
||||
let config = HypervisorVmConfig {
|
||||
#[cfg(feature = "tdx")]
|
||||
tdx_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
sev_snp_enabled,
|
||||
#[cfg(feature = "sev_snp")]
|
||||
mem_size,
|
||||
};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "tdx")] {
|
||||
// Passing KVM_X86_TDX_VM: 1 if tdx_enabled is true
|
||||
// Otherwise KVM_X86_LEGACY_VM: 0
|
||||
// value of tdx_enabled is mapped to KVM_X86_TDX_VM or KVM_X86_LEGACY_VM
|
||||
let vm = hypervisor
|
||||
.create_vm_with_type(u64::from(tdx_enabled))
|
||||
.unwrap();
|
||||
} else if #[cfg(feature = "sev_snp")] {
|
||||
// Passing SEV_SNP_ENABLED: 1 if sev_snp_enabled is true
|
||||
// Otherwise SEV_SNP_DISABLED: 0
|
||||
// value of sev_snp_enabled is mapped to SEV_SNP_ENABLED for true or SEV_SNP_DISABLED for false
|
||||
let vm = hypervisor
|
||||
.create_vm_with_type_and_memory(u64::from(sev_snp_enabled), mem_size)
|
||||
.unwrap();
|
||||
} else {
|
||||
let vm = hypervisor.create_vm().unwrap();
|
||||
}
|
||||
}
|
||||
let vm = hypervisor.create_vm(config).unwrap();
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
@@ -3497,7 +3487,7 @@ mod tests {
|
||||
.collect();
|
||||
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let gic = vm
|
||||
.create_vgic(Gic::create_default_config(1))
|
||||
.expect("Cannot create gic");
|
||||
@@ -3539,7 +3529,9 @@ pub fn test_vm() {
|
||||
let mem = GuestMemoryMmap::from_ranges(&[(load_addr, mem_size)]).unwrap();
|
||||
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM creation failed");
|
||||
let vm = hv
|
||||
.create_vm(HypervisorVmConfig::default())
|
||||
.expect("new VM creation failed");
|
||||
|
||||
for (index, region) in mem.iter().enumerate() {
|
||||
let mem_region = vm.make_user_memory_region(
|
||||
|
||||
Reference in New Issue
Block a user