Trait arch::LinuxArch

source ·
pub trait LinuxArch {
    type Error: StdError;
    type ArchMemoryLayout;

    // Required methods
    fn arch_memory_layout(
        components: &VmComponents
    ) -> Result<Self::ArchMemoryLayout, Self::Error>;
    fn guest_memory_layout(
        components: &VmComponents,
        arch_memory_layout: &Self::ArchMemoryLayout,
        hypervisor: &impl Hypervisor
    ) -> Result<Vec<(GuestAddress, u64, MemoryRegionOptions)>, Self::Error>;
    fn get_system_allocator_config<V: Vm>(
        vm: &V,
        arch_memory_layout: &Self::ArchMemoryLayout
    ) -> SystemAllocatorConfig;
    fn build_vm<V, Vcpu>(
        components: VmComponents,
        arch_memory_layout: &Self::ArchMemoryLayout,
        vm_evt_wrtube: &SendTube,
        system_allocator: &mut SystemAllocator,
        serial_parameters: &BTreeMap<(SerialHardware, u8), SerialParameters>,
        serial_jail: Option<Minijail>,
        battery: (Option<BatteryType>, Option<Minijail>),
        vm: V,
        ramoops_region: Option<RamoopsRegion>,
        devices: Vec<(Box<dyn BusDeviceObj>, Option<Minijail>)>,
        irq_chip: &mut dyn IrqChipArch,
        vcpu_ids: &mut Vec<usize>,
        dump_device_tree_blob: Option<PathBuf>,
        debugcon_jail: Option<Minijail>,
        pflash_jail: Option<Minijail>,
        fw_cfg_jail: Option<Minijail>,
        swap_controller: &mut Option<SwapController>,
        guest_suspended_cvar: Option<Arc<(Mutex<bool>, Condvar)>>,
        device_tree_overlays: Vec<DtbOverlay>,
        fdt_position: Option<FdtPosition>,
        no_pmu: bool
    ) -> Result<RunnableLinuxVm<V, Vcpu>, Self::Error>
       where V: VmArch,
             Vcpu: VcpuArch;
    fn configure_vcpu<V: Vm>(
        vm: &V,
        hypervisor: &dyn HypervisorArch,
        irq_chip: &mut dyn IrqChipArch,
        vcpu: &mut dyn VcpuArch,
        vcpu_init: VcpuInitArch,
        vcpu_id: usize,
        num_cpus: usize,
        cpu_config: Option<CpuConfigArch>
    ) -> Result<(), Self::Error>;
    fn register_pci_device<V: VmArch, Vcpu: VcpuArch>(
        linux: &mut RunnableLinuxVm<V, Vcpu>,
        device: Box<dyn PciDevice>,
        minijail: Option<Minijail>,
        resources: &mut SystemAllocator,
        hp_control_tube: &Sender<PciRootCommand>,
        swap_controller: &mut Option<SwapController>
    ) -> Result<PciAddress, Self::Error>;
    fn get_host_cpu_frequencies_khz(
    ) -> Result<BTreeMap<usize, Vec<u32>>, Self::Error>;
    fn get_host_cpu_max_freq_khz() -> Result<BTreeMap<usize, u32>, Self::Error>;
    fn get_host_cpu_capacity() -> Result<BTreeMap<usize, u32>, Self::Error>;
    fn get_host_cpu_clusters() -> Result<Vec<CpuSet>, Self::Error>;
}
Expand description

Trait which is implemented for each Linux Architecture in order to set up the memory, cpus, and system devices and to boot the kernel.

Required Associated Types§

Required Methods§

source

fn arch_memory_layout( components: &VmComponents ) -> Result<Self::ArchMemoryLayout, Self::Error>

Decide architecture specific memory layout details to be used by later stages of the VM setup.

source

fn guest_memory_layout( components: &VmComponents, arch_memory_layout: &Self::ArchMemoryLayout, hypervisor: &impl Hypervisor ) -> Result<Vec<(GuestAddress, u64, MemoryRegionOptions)>, Self::Error>

Returns a Vec of the valid memory addresses as pairs of address and length. These should be used to configure the GuestMemory structure for the platform.

§Arguments
  • components - Parts used to determine the memory layout.
source

fn get_system_allocator_config<V: Vm>( vm: &V, arch_memory_layout: &Self::ArchMemoryLayout ) -> SystemAllocatorConfig

Gets the configuration for a new SystemAllocator that fits the given Vm’s memory layout.

This is the per-architecture template for constructing the SystemAllocator. Platform agnostic modifications may be made to this configuration, but the final SystemAllocator will be at least as strict as this configuration.

§Arguments
  • vm - The virtual machine to be used as a template for the SystemAllocator.
source

fn build_vm<V, Vcpu>( components: VmComponents, arch_memory_layout: &Self::ArchMemoryLayout, vm_evt_wrtube: &SendTube, system_allocator: &mut SystemAllocator, serial_parameters: &BTreeMap<(SerialHardware, u8), SerialParameters>, serial_jail: Option<Minijail>, battery: (Option<BatteryType>, Option<Minijail>), vm: V, ramoops_region: Option<RamoopsRegion>, devices: Vec<(Box<dyn BusDeviceObj>, Option<Minijail>)>, irq_chip: &mut dyn IrqChipArch, vcpu_ids: &mut Vec<usize>, dump_device_tree_blob: Option<PathBuf>, debugcon_jail: Option<Minijail>, pflash_jail: Option<Minijail>, fw_cfg_jail: Option<Minijail>, swap_controller: &mut Option<SwapController>, guest_suspended_cvar: Option<Arc<(Mutex<bool>, Condvar)>>, device_tree_overlays: Vec<DtbOverlay>, fdt_position: Option<FdtPosition>, no_pmu: bool ) -> Result<RunnableLinuxVm<V, Vcpu>, Self::Error>
where V: VmArch, Vcpu: VcpuArch,

Takes VmComponents and generates a RunnableLinuxVm.

§Arguments
  • components - Parts to use to build the VM.
  • vm_evt_wrtube - Tube used by sub-devices to request that crosvm exit because guest wants to stop/shut down or requested reset.
  • system_allocator - Allocator created by this trait’s implementation of get_system_allocator_config.
  • serial_parameters - Definitions for how the serial devices should be configured.
  • serial_jail - Jail used for serial devices created here.
  • battery - Defines what battery device will be created.
  • vm - A VM implementation to build upon.
  • ramoops_region - Region allocated for ramoops.
  • devices - The devices to be built into the VM.
  • irq_chip - The IRQ chip implemention for the VM.
  • debugcon_jail - Jail used for debugcon devices created here.
  • pflash_jail - Jail used for pflash device created here.
  • fw_cfg_jail - Jail used for fw_cfg device created here.
  • device_tree_overlays - Device tree overlay binaries
source

fn configure_vcpu<V: Vm>( vm: &V, hypervisor: &dyn HypervisorArch, irq_chip: &mut dyn IrqChipArch, vcpu: &mut dyn VcpuArch, vcpu_init: VcpuInitArch, vcpu_id: usize, num_cpus: usize, cpu_config: Option<CpuConfigArch> ) -> Result<(), Self::Error>

Configures the vcpu and should be called once per vcpu from the vcpu’s thread.

§Arguments
  • vm - The virtual machine object.
  • hypervisor - The Hypervisor that created the vcpu.
  • irq_chip - The IrqChip associated with this vm.
  • vcpu - The VCPU object to configure.
  • vcpu_init - The data required to initialize VCPU registers and other state.
  • vcpu_id - The id of the given vcpu.
  • num_cpus - Number of virtual CPUs the guest will have.
  • cpu_config - CPU feature configurations.
source

fn register_pci_device<V: VmArch, Vcpu: VcpuArch>( linux: &mut RunnableLinuxVm<V, Vcpu>, device: Box<dyn PciDevice>, minijail: Option<Minijail>, resources: &mut SystemAllocator, hp_control_tube: &Sender<PciRootCommand>, swap_controller: &mut Option<SwapController> ) -> Result<PciAddress, Self::Error>

Configures and add a pci device into vm

source

fn get_host_cpu_frequencies_khz( ) -> Result<BTreeMap<usize, Vec<u32>>, Self::Error>

Returns frequency map for each of the host’s logical cores.

source

fn get_host_cpu_max_freq_khz() -> Result<BTreeMap<usize, u32>, Self::Error>

Returns max-freq map of the host’s logical cores.

source

fn get_host_cpu_capacity() -> Result<BTreeMap<usize, u32>, Self::Error>

Returns capacity map of the host’s logical cores.

source

fn get_host_cpu_clusters() -> Result<Vec<CpuSet>, Self::Error>

Returns cluster masks for each of the host’s logical cores.

Object Safety§

This trait is not object safe.

Implementors§