mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
arch: return system allocator config
Have the arch code return the SystemAllocatorConfig instead of a SystemAllocator. This will be used to allow the core code to apply additional restrictions on top of the arch code's restrictions. BUG=b:181736020 TEST=compiles Change-Id: I4d9ca277f039586e664648492c8744967dcd2ee5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3516665 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Junichi Uekawa <uekawa@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: David Stevens <stevensd@chromium.org>
This commit is contained in:
parent
eba2940049
commit
097623dce4
6 changed files with 36 additions and 17 deletions
|
@ -207,8 +207,11 @@ impl arch::LinuxArch for AArch64 {
|
|||
Ok(arch_memory_regions(components.memory_size))
|
||||
}
|
||||
|
||||
fn create_system_allocator<V: Vm>(vm: &V) -> SystemAllocator {
|
||||
Self::get_resource_allocator(vm.get_memory().memory_size(), vm.get_guest_phys_addr_bits())
|
||||
fn get_system_allocator_config<V: Vm>(vm: &V) -> SystemAllocatorConfig {
|
||||
Self::get_resource_allocator_config(
|
||||
vm.get_memory().memory_size(),
|
||||
vm.get_guest_phys_addr_bits(),
|
||||
)
|
||||
}
|
||||
|
||||
fn build_vm<V, Vcpu>(
|
||||
|
@ -523,13 +526,16 @@ impl AArch64 {
|
|||
cmdline
|
||||
}
|
||||
|
||||
/// Returns a system resource allocator.
|
||||
/// Returns a system resource allocator configuration.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `mem_size` - Size of guest memory (RAM) in bytes.
|
||||
/// * `guest_phys_addr_bits` - Size of guest physical addresses (IPA) in bits.
|
||||
fn get_resource_allocator(mem_size: u64, guest_phys_addr_bits: u8) -> SystemAllocator {
|
||||
fn get_resource_allocator_config(
|
||||
mem_size: u64,
|
||||
guest_phys_addr_bits: u8,
|
||||
) -> SystemAllocatorConfig {
|
||||
let guest_phys_end = 1u64 << guest_phys_addr_bits;
|
||||
// The platform MMIO region is immediately past the end of RAM.
|
||||
let plat_mmio_base = AARCH64_PHYS_MEM_START + mem_size;
|
||||
|
@ -544,7 +550,7 @@ impl AArch64 {
|
|||
guest_phys_end, high_mmio_base,
|
||||
);
|
||||
});
|
||||
SystemAllocator::new(SystemAllocatorConfig {
|
||||
SystemAllocatorConfig {
|
||||
io: None,
|
||||
low_mmio: MemRegion {
|
||||
base: AARCH64_MMIO_BASE,
|
||||
|
@ -559,8 +565,7 @@ impl AArch64 {
|
|||
size: plat_mmio_size,
|
||||
}),
|
||||
first_irq: AARCH64_IRQ_BASE,
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// This adds any early platform devices for this architecture.
|
||||
|
|
|
@ -26,7 +26,7 @@ use devices::{
|
|||
use hypervisor::{IoEventAddress, ProtectionType, Vm};
|
||||
use minijail::Minijail;
|
||||
use remain::sorted;
|
||||
use resources::{MmioType, SystemAllocator};
|
||||
use resources::{MmioType, SystemAllocator, SystemAllocatorConfig};
|
||||
use sync::Mutex;
|
||||
use thiserror::Error;
|
||||
use vm_control::{BatControl, BatteryType, PmResource};
|
||||
|
@ -151,12 +151,16 @@ pub trait LinuxArch {
|
|||
components: &VmComponents,
|
||||
) -> std::result::Result<Vec<(GuestAddress, u64)>, Self::Error>;
|
||||
|
||||
/// Creates a new `SystemAllocator` that fits the given `Vm`'s memory layout.
|
||||
/// 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`.
|
||||
fn create_system_allocator<V: Vm>(vm: &V) -> SystemAllocator;
|
||||
fn get_system_allocator_config<V: Vm>(vm: &V) -> SystemAllocatorConfig;
|
||||
|
||||
/// Takes `VmComponents` and generates a `RunnableLinuxVm`.
|
||||
///
|
||||
|
@ -168,7 +172,7 @@ pub trait LinuxArch {
|
|||
/// * `reset_evt` - Event used by sub-devices to request that crosvm exit because guest
|
||||
/// requested reset.
|
||||
/// * `system_allocator` - Allocator created by this trait's implementation of
|
||||
/// `create_system_allocator`.
|
||||
/// `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.
|
||||
|
|
|
@ -29,8 +29,16 @@ pub struct SystemAllocatorConfig {
|
|||
/// IO ports. Only for x86_64.
|
||||
pub io: Option<MemRegion>,
|
||||
/// Low (<=4GB) MMIO region.
|
||||
///
|
||||
/// Parts of this region may be reserved or otherwise excluded from the
|
||||
/// created SystemAllocator's MmioType::Low allocator. However, no new
|
||||
/// regions will be added.
|
||||
pub low_mmio: MemRegion,
|
||||
/// High (>4GB) MMIO region.
|
||||
///
|
||||
/// Parts of this region may be reserved or otherwise excluded from the
|
||||
/// created SystemAllocator's MmioType::High allocator. However, no new
|
||||
/// regions will be added.
|
||||
pub high_mmio: MemRegion,
|
||||
/// Platform MMIO space. Only for ARM.
|
||||
pub platform_mmio: Option<MemRegion>,
|
||||
|
|
|
@ -1156,7 +1156,8 @@ where
|
|||
let reset_evt = Event::new().context("failed to create event")?;
|
||||
let crash_evt = Event::new().context("failed to create event")?;
|
||||
let (panic_rdtube, panic_wrtube) = Tube::pair().context("failed to create tube")?;
|
||||
let mut sys_allocator = Arch::create_system_allocator(&vm);
|
||||
let mut sys_allocator = SystemAllocator::new(Arch::get_system_allocator_config(&vm))
|
||||
.context("failed to create system allocator")?;
|
||||
|
||||
// Allocate the ramoops region first. AArch64::build_vm() assumes this.
|
||||
let ramoops_region = match &components.pstore {
|
||||
|
|
|
@ -391,11 +391,11 @@ impl arch::LinuxArch for X8664arch {
|
|||
Ok(arch_memory_regions(components.memory_size, bios_size))
|
||||
}
|
||||
|
||||
fn create_system_allocator<V: Vm>(vm: &V) -> SystemAllocator {
|
||||
fn get_system_allocator_config<V: Vm>(vm: &V) -> SystemAllocatorConfig {
|
||||
let guest_mem = vm.get_memory();
|
||||
let high_mmio_start = Self::get_high_mmio_base(guest_mem);
|
||||
let high_mmio_size = Self::get_high_mmio_size(vm);
|
||||
SystemAllocator::new(SystemAllocatorConfig {
|
||||
SystemAllocatorConfig {
|
||||
io: Some(MemRegion {
|
||||
base: 0xc000,
|
||||
size: 0x4000,
|
||||
|
@ -410,8 +410,7 @@ impl arch::LinuxArch for X8664arch {
|
|||
},
|
||||
platform_mmio: None,
|
||||
first_irq: X86_64_IRQ_BASE,
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn build_vm<V, Vcpu>(
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
use arch::LinuxArch;
|
||||
use devices::IrqChipX86_64;
|
||||
use hypervisor::{HypervisorX86_64, ProtectionType, VcpuExit, VcpuX86_64, VmX86_64};
|
||||
use resources::SystemAllocator;
|
||||
use vm_memory::{GuestAddress, GuestMemory};
|
||||
|
||||
use super::cpuid::setup_cpuid;
|
||||
|
@ -102,7 +103,8 @@ where
|
|||
let guest_mem = GuestMemory::new(&arch_mem_regions).unwrap();
|
||||
|
||||
let (hyp, mut vm) = create_vm(guest_mem.clone());
|
||||
let mut resources = X8664arch::create_system_allocator(&vm);
|
||||
let mut resources = SystemAllocator::new(X8664arch::get_system_allocator_config(&vm))
|
||||
.expect("failed to create system allocator");
|
||||
let (irqchip_tube, device_tube) = Tube::pair().expect("failed to create irq tube");
|
||||
|
||||
let mut irq_chip = create_irq_chip(vm.try_clone().expect("failed to clone vm"), 1, device_tube);
|
||||
|
|
Loading…
Reference in a new issue