From 8155be2e6b80e3d8c9eca4e21a2b48e968d519b0 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Fri, 14 Jan 2022 18:21:08 +0000 Subject: [PATCH] arch: aarch64: vm_memory is not required when configuring vcpu Drop the unused parameter throughout the code base. Also take the chance to drop a needless clone. No functional change intended. Signed-off-by: Wei Liu --- arch/src/aarch64/mod.rs | 14 +++----------- arch/src/aarch64/regs.rs | 8 +------- vmm/src/cpu.rs | 19 ++++++------------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index 0a915d423..2d9caa353 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -21,9 +21,7 @@ use std::collections::HashMap; use std::convert::TryInto; use std::fmt::Debug; use std::sync::Arc; -use vm_memory::{ - Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, GuestUsize, -}; +use vm_memory::{Address, GuestAddress, GuestMemory, GuestUsize}; /// Errors thrown while configuring aarch64 system. #[derive(Debug)] @@ -66,16 +64,10 @@ pub fn configure_vcpu( fd: &Arc, id: u8, kernel_entry_point: Option, - vm_memory: &GuestMemoryAtomic, ) -> super::Result { if let Some(kernel_entry_point) = kernel_entry_point { - regs::setup_regs( - fd, - id, - kernel_entry_point.entry_addr.raw_value(), - &vm_memory.memory(), - ) - .map_err(Error::RegsConfiguration)?; + regs::setup_regs(fd, id, kernel_entry_point.entry_addr.raw_value()) + .map_err(Error::RegsConfiguration)?; } let mpidr = fd.read_mpidr().map_err(Error::VcpuRegMpidr)?; diff --git a/arch/src/aarch64/regs.rs b/arch/src/aarch64/regs.rs index 628fd977d..bc9e449fa 100644 --- a/arch/src/aarch64/regs.rs +++ b/arch/src/aarch64/regs.rs @@ -6,7 +6,6 @@ // found in the THIRD-PARTY file. use super::get_fdt_addr; -use crate::GuestMemoryMmap; use hypervisor::kvm::kvm_bindings::{ kvm_regs, user_pt_regs, KVM_REG_ARM64, KVM_REG_ARM_CORE, KVM_REG_SIZE_U64, }; @@ -43,12 +42,7 @@ const PSTATE_FAULT_BITS_64: u64 = PSR_MODE_EL1h | PSR_A_BIT | PSR_F_BIT | PSR_I_ /// * `cpu_id` - Index of current vcpu. /// * `boot_ip` - Starting instruction pointer. /// * `mem` - Reserved DRAM for current VM. -pub fn setup_regs( - vcpu: &Arc, - cpu_id: u8, - boot_ip: u64, - _mem: &GuestMemoryMmap, -) -> Result<()> { +pub fn setup_regs(vcpu: &Arc, cpu_id: u8, boot_ip: u64) -> Result<()> { let kreg_off = offset__of!(kvm_regs, regs); // Get the register index of the PSTATE (Processor State) register. diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index df21d05c5..579ca28d6 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -265,14 +265,14 @@ impl Vcpu { &mut self, #[cfg(target_arch = "aarch64")] vm: &Arc, kernel_entry_point: Option, - vm_memory: &GuestMemoryAtomic, + #[cfg(target_arch = "x86_64")] vm_memory: &GuestMemoryAtomic, #[cfg(target_arch = "x86_64")] cpuid: CpuId, #[cfg(target_arch = "x86_64")] kvm_hyperv: bool, ) -> Result<()> { #[cfg(target_arch = "aarch64")] { self.init(vm)?; - self.mpidr = arch::configure_vcpu(&self.vcpu, self.id, kernel_entry_point, vm_memory) + self.mpidr = arch::configure_vcpu(&self.vcpu, self.id, kernel_entry_point) .map_err(Error::VcpuConfiguration)?; } info!("Configuring vCPU: cpu_id = {}", self.id); @@ -656,19 +656,17 @@ impl CpuManager { vcpu.restore(snapshot).expect("Failed to restore vCPU"); } else { - let vm_memory = self.vm_memory.clone(); - #[cfg(target_arch = "x86_64")] vcpu.configure( entry_point, - &vm_memory, + &self.vm_memory, self.cpuid.clone(), self.config.kvm_hyperv, ) .expect("Failed to configure vCPU"); #[cfg(target_arch = "aarch64")] - vcpu.configure(&self.vm, entry_point, &vm_memory) + vcpu.configure(&self.vm, entry_point) .expect("Failed to configure vCPU"); } @@ -1757,13 +1755,8 @@ mod tests { let hv = hypervisor::new().unwrap(); let vm = hv.create_vm().unwrap(); let vcpu = vm.create_vcpu(0, None).unwrap(); - let regions = vec![( - GuestAddress(layout::RAM_64BIT_START), - (layout::FDT_MAX_SIZE + 0x1000) as usize, - )]; - let mem = GuestMemoryMmap::from_ranges(®ions).expect("Cannot initialize memory"); - let res = setup_regs(&vcpu, 0, 0x0, &mem); + let res = setup_regs(&vcpu, 0, 0x0); // Must fail when vcpu is not initialized yet. assert!(res.is_err()); @@ -1771,7 +1764,7 @@ mod tests { vm.get_preferred_target(&mut kvi).unwrap(); vcpu.vcpu_init(&kvi).unwrap(); - assert!(setup_regs(&vcpu, 0, 0x0, &mem).is_ok()); + assert!(setup_regs(&vcpu, 0, 0x0).is_ok()); } #[test]