From 0319a4a09aab02c69692a0f8966ce3814d4e8660 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 6 Nov 2019 17:20:55 +0000 Subject: [PATCH] arch: vmm: Move ACPI tables creation to vmm crate Remove ACPI table creation from arch crate to the vmm crate simplifying arch::configure_system() GuestAddress(0) is used to mean no RSDP table rather than adding complexity with a conditional argument or an Option type as it will evaluate to a zero value which would be the default anyway. Signed-off-by: Rob Bradford --- arch/Cargo.toml | 1 - arch/src/aarch64/mod.rs | 3 +- arch/src/x86_64/mod.rs | 70 +++------------------------- vmm/Cargo.toml | 2 +- {arch/src/x86_64 => vmm/src}/acpi.rs | 2 +- vmm/src/lib.rs | 3 ++ vmm/src/vm.rs | 39 ++++++++++++---- 7 files changed, 43 insertions(+), 77 deletions(-) rename {arch/src/x86_64 => vmm/src}/acpi.rs (99%) diff --git a/arch/Cargo.toml b/arch/Cargo.toml index 37a34393a..b180d120b 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -5,7 +5,6 @@ authors = ["The Chromium OS Authors"] [features] default = [] -acpi = ["acpi_tables"] [dependencies] byteorder = "1.3.2" diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index fa016278a..c1059b769 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -16,8 +16,7 @@ pub fn configure_system( _cmdline_addr: GuestAddress, _cmdline_size: usize, _num_cpus: u8, - _serial_enabled: bool, - _virt_iommu: Option<(u32, &[u32])>, + _rsdp_addr: Option, ) -> super::Result<()> { Ok(()) } diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index fc09b8fc9..de385f4ed 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -5,9 +5,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-BSD-3-Clause file. -#[cfg(feature = "acpi")] -mod acpi; - mod gdt; pub mod interrupts; pub mod layout; @@ -111,9 +108,7 @@ pub fn configure_system( cmdline_size: usize, num_cpus: u8, setup_hdr: Option, - _serial_enabled: bool, - _end_of_range: GuestAddress, - _virt_iommu: Option<(u32, &[u32])>, + rsdp_addr: Option, ) -> super::Result<()> { const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55; const KERNEL_HDR_MAGIC: u32 = 0x53726448; @@ -172,21 +167,7 @@ pub fn configure_system( E820_RESERVED, )?; - #[cfg(feature = "acpi")] - { - let start_of_device_area = if mem_end < layout::MEM_32BIT_RESERVED_START { - layout::RAM_64BIT_START - } else { - guest_mem.end_addr().unchecked_add(1) - }; - let rsdp_addr = acpi::create_acpi_tables( - guest_mem, - num_cpus, - _serial_enabled, - start_of_device_area, - _end_of_range, - _virt_iommu, - ); + if let Some(rsdp_addr) = rsdp_addr { params.0.acpi_rsdp_addr = rsdp_addr.0; } @@ -246,16 +227,7 @@ mod tests { fn test_system_configuration() { let no_vcpus = 4; let gm = GuestMemoryMmap::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); - let config_err = configure_system( - &gm, - GuestAddress(0), - 0, - 1, - None, - false, - GuestAddress((1 << 36) - 1), - None, - ); + let config_err = configure_system(&gm, GuestAddress(0), 0, 1, None, None); assert!(config_err.is_err()); assert_eq!( config_err.unwrap_err(), @@ -273,17 +245,7 @@ mod tests { .map(|r| (r.0, r.1)) .collect(); let gm = GuestMemoryMmap::new(&ram_regions).unwrap(); - configure_system( - &gm, - GuestAddress(0), - 0, - no_vcpus, - None, - false, - GuestAddress((1 << 36) - 1), - None, - ) - .unwrap(); + configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap(); // Now assigning some memory that is equal to the start of the 32bit memory hole. let mem_size = 3328 << 20; @@ -294,17 +256,7 @@ mod tests { .map(|r| (r.0, r.1)) .collect(); let gm = GuestMemoryMmap::new(&ram_regions).unwrap(); - configure_system( - &gm, - GuestAddress(0), - 0, - no_vcpus, - None, - false, - GuestAddress((1 << 36) - 1), - None, - ) - .unwrap(); + configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap(); // Now assigning some memory that falls after the 32bit memory hole. let mem_size = 3330 << 20; @@ -315,17 +267,7 @@ mod tests { .map(|r| (r.0, r.1)) .collect(); let gm = GuestMemoryMmap::new(&ram_regions).unwrap(); - configure_system( - &gm, - GuestAddress(0), - 0, - no_vcpus, - None, - false, - GuestAddress((1 << 36) - 1), - None, - ) - .unwrap(); + configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap(); } #[test] diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index b83b37863..bbde7444b 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [features] default = [] -acpi = ["acpi_tables","devices/acpi", "arch/acpi"] +acpi = ["acpi_tables","devices/acpi"] pci_support = ["pci", "vfio", "vm-virtio/pci_support"] mmio_support = ["vm-virtio/mmio_support"] cmos = ["devices/cmos"] diff --git a/arch/src/x86_64/acpi.rs b/vmm/src/acpi.rs similarity index 99% rename from arch/src/x86_64/acpi.rs rename to vmm/src/acpi.rs index e4c345f05..40ee93ca0 100644 --- a/arch/src/x86_64/acpi.rs +++ b/vmm/src/acpi.rs @@ -14,7 +14,7 @@ use vm_memory::{Address, ByteValued, Bytes}; use std::convert::TryInto; -use super::layout; +use arch::layout; #[repr(packed)] struct LocalAPIC { diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index dd128fd7c..6cf830905 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -30,6 +30,9 @@ pub mod config; pub mod device_manager; pub mod vm; +#[cfg(feature = "acpi")] +mod acpi; + /// Errors associated with VMM management #[derive(Debug)] #[allow(clippy::large_enum_variant)] diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index b0a72538c..fb09fc3aa 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -23,7 +23,7 @@ extern crate vm_allocator; extern crate vm_memory; extern crate vm_virtio; -use crate::config::{ConsoleOutputMode, VmConfig}; +use crate::config::VmConfig; use crate::device_manager::{get_win_size, Console, DeviceManager, DeviceManagerError}; use arch::RegionType; use devices::ioapic; @@ -768,7 +768,34 @@ impl Vm { ) .map_err(|_| Error::CmdLine)?; let vcpu_count = self.config.cpus.cpu_count; - let end_of_range = GuestAddress((1 << get_host_cpu_phys_bits()) - 1); + + #[allow(unused_mut, unused_assignments)] + let mut rsdp_addr: Option = None; + + #[cfg(feature = "acpi")] + { + rsdp_addr = Some({ + let end_of_range = GuestAddress((1 << get_host_cpu_phys_bits()) - 1); + + let mem_end = mem.end_addr(); + let start_of_device_area = if mem_end < arch::layout::MEM_32BIT_RESERVED_START { + arch::layout::RAM_64BIT_START + } else { + mem_end.unchecked_add(1) + }; + + use crate::config::ConsoleOutputMode; + crate::acpi::create_acpi_tables( + &mem, + vcpu_count, + self.config.serial.mode != ConsoleOutputMode::Off, + start_of_device_area, + end_of_range, + self.devices.virt_iommu(), + ) + }); + } + match entry_addr.setup_header { Some(hdr) => { arch::configure_system( @@ -777,9 +804,7 @@ impl Vm { cmdline_cstring.to_bytes().len() + 1, vcpu_count, Some(hdr), - self.config.serial.mode != ConsoleOutputMode::Off, - end_of_range, - self.devices.virt_iommu(), + rsdp_addr, ) .map_err(|_| Error::CmdLine)?; @@ -798,9 +823,7 @@ impl Vm { cmdline_cstring.to_bytes().len() + 1, vcpu_count, None, - self.config.serial.mode != ConsoleOutputMode::Off, - end_of_range, - self.devices.virt_iommu(), + rsdp_addr, ) .map_err(|_| Error::CmdLine)?;