arch: Fix AArch64 clippy warnings of arch crate

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao 2020-08-23 15:44:57 +08:00 committed by Sebastien Boeuf
parent 527e8e7b1d
commit 46b8f38987
7 changed files with 33 additions and 33 deletions

View File

@ -90,12 +90,12 @@ pub enum Error {
type Result<T> = result::Result<T, Error>;
/// Creates the flattened device tree for this aarch64 VM.
pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug>(
pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug, S: ::std::hash::BuildHasher>(
guest_mem: &GuestMemoryMmap,
cmdline: &CStr,
vcpu_mpidr: Vec<u64>,
device_info: &HashMap<(DeviceType, String), T>,
gic_device: &Box<dyn GICDevice>,
device_info: &HashMap<(DeviceType, String), T, S>,
gic_device: &dyn GICDevice,
initrd: &Option<InitramfsConfig>,
pci_space_address: &Option<(u64, u64)>,
) -> Result<Vec<u8>> {
@ -311,7 +311,7 @@ fn generate_prop64(cells: &[u64]) -> Vec<u8> {
}
// Following are the auxiliary function for creating the different nodes that we append to our FDT.
fn create_cpu_nodes(fdt: &mut Vec<u8>, vcpu_mpidr: &Vec<u64>) -> Result<()> {
fn create_cpu_nodes(fdt: &mut Vec<u8>, vcpu_mpidr: &[u64]) -> Result<()> {
// See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml.
append_begin_node(fdt, "cpus")?;
// As per documentation, on ARM v8 64-bit systems value should be set to 2.
@ -319,7 +319,7 @@ fn create_cpu_nodes(fdt: &mut Vec<u8>, vcpu_mpidr: &Vec<u64>) -> Result<()> {
append_property_u32(fdt, "#size-cells", 0x0)?;
let num_cpus = vcpu_mpidr.len();
for cpu_index in 0..num_cpus {
for (cpu_index, mpidr) in vcpu_mpidr.iter().enumerate().take(num_cpus) {
let cpu_name = format!("cpu@{:x}", cpu_index);
append_begin_node(fdt, &cpu_name)?;
append_property_string(fdt, "device_type", "cpu")?;
@ -330,7 +330,7 @@ fn create_cpu_nodes(fdt: &mut Vec<u8>, vcpu_mpidr: &Vec<u64>) -> Result<()> {
}
// Set the field to first 24 bits of the MPIDR - Multiprocessor Affinity Register.
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0488c/BABHBJCI.html.
append_property_u64(fdt, "reg", vcpu_mpidr[cpu_index] & 0x7FFFFF)?;
append_property_u64(fdt, "reg", mpidr & 0x7FFFFF)?;
append_end_node(fdt)?;
}
append_end_node(fdt)?;
@ -376,7 +376,7 @@ fn create_chosen_node(
Ok(())
}
fn create_gic_node(fdt: &mut Vec<u8>, gic_device: &Box<dyn GICDevice>) -> Result<()> {
fn create_gic_node(fdt: &mut Vec<u8>, gic_device: &dyn GICDevice) -> Result<()> {
let gic_reg_prop = generate_prop64(gic_device.device_properties());
append_begin_node(fdt, "intc")?;
@ -521,9 +521,9 @@ fn create_rtc_node<T: DeviceInfoForFDT + Clone + Debug>(
Ok(())
}
fn create_devices_node<T: DeviceInfoForFDT + Clone + Debug>(
fn create_devices_node<T: DeviceInfoForFDT + Clone + Debug, S: ::std::hash::BuildHasher>(
fdt: &mut Vec<u8>,
dev_info: &HashMap<(DeviceType, String), T>,
dev_info: &HashMap<(DeviceType, String), T, S>,
) -> Result<()> {
// Create one temp Vec to store all virtio devices
let mut ordered_virtio_device: Vec<&T> = Vec::new();

View File

@ -71,7 +71,7 @@ pub mod kvm {
/// Setup the device-specific attributes
fn init_device_attributes(
vm: &Arc<dyn hypervisor::Vm>,
gic_device: &Box<dyn GICDevice>,
gic_device: &dyn GICDevice,
) -> Result<()>;
/// Initialize a GIC device
@ -95,10 +95,10 @@ pub mod kvm {
flags: u32,
) -> Result<()> {
let attr = kvm_bindings::kvm_device_attr {
group: group,
attr: attr,
addr: addr,
flags: flags,
group,
attr,
addr,
flags,
};
device
.set_device_attr(&attr)
@ -108,7 +108,7 @@ pub mod kvm {
}
/// Finalize the setup of a GIC device
fn finalize_device(gic_device: &Box<dyn GICDevice>) -> Result<()> {
fn finalize_device(gic_device: &dyn GICDevice) -> Result<()> {
/* We need to tell the kernel how many irqs to support with this vgic.
* See the `layout` module for details.
*/
@ -142,9 +142,9 @@ pub mod kvm {
let device = Self::create_device(vgic_fd, vcpu_count);
Self::init_device_attributes(vm, &device)?;
Self::init_device_attributes(vm, &*device)?;
Self::finalize_device(&device)?;
Self::finalize_device(&*device)?;
Ok(device)
}

View File

@ -84,20 +84,20 @@ pub mod kvm {
vcpu_count: u64,
) -> Box<dyn GICDevice> {
Box::new(KvmGICv2 {
device: device,
device,
properties: [
KvmGICv2::get_dist_addr(),
KvmGICv2::get_dist_size(),
KvmGICv2::get_cpu_addr(),
KvmGICv2::get_cpu_size(),
],
vcpu_count: vcpu_count,
vcpu_count,
})
}
fn init_device_attributes(
_vm: &Arc<dyn hypervisor::Vm>,
gic_device: &Box<dyn GICDevice>,
gic_device: &dyn GICDevice,
) -> Result<()> {
/* Setting up the distributor attribute.
We are placing the GIC below 1GB so we need to substract the size of the distributor. */

View File

@ -84,20 +84,20 @@ pub mod kvm {
vcpu_count: u64,
) -> Box<dyn GICDevice> {
Box::new(KvmGICv3 {
device: device,
device,
properties: [
KvmGICv3::get_dist_addr(),
KvmGICv3::get_dist_size(),
KvmGICv3::get_redists_addr(vcpu_count),
KvmGICv3::get_redists_size(vcpu_count),
],
vcpu_count: vcpu_count,
vcpu_count,
})
}
fn init_device_attributes(
_vm: &Arc<dyn hypervisor::Vm>,
gic_device: &Box<dyn GICDevice>,
gic_device: &dyn GICDevice,
) -> Result<()> {
/* Setting up the distributor attribute.
We are placing the GIC below 1GB so we need to substract the size of the distributor.
@ -117,8 +117,7 @@ pub mod kvm {
gic_device.device(),
kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
u64::from(kvm_bindings::KVM_VGIC_V3_ADDR_TYPE_REDIST),
&KvmGICv3::get_redists_addr(u64::from(gic_device.vcpu_count())) as *const u64
as u64,
&KvmGICv3::get_redists_addr(gic_device.vcpu_count()) as *const u64 as u64,
0,
)?;

View File

@ -80,7 +80,7 @@ pub mod kvm {
vcpu_count: u64,
) -> Box<dyn GICDevice> {
Box::new(KvmGICv3ITS {
device: device,
device,
gic_properties: [
KvmGICv3::get_dist_addr(),
KvmGICv3::get_dist_size(),
@ -91,13 +91,13 @@ pub mod kvm {
KvmGICv3ITS::get_msi_addr(vcpu_count),
KvmGICv3ITS::get_msi_size(),
],
vcpu_count: vcpu_count,
vcpu_count,
})
}
fn init_device_attributes(
vm: &Arc<dyn hypervisor::Vm>,
gic_device: &Box<dyn GICDevice>,
gic_device: &dyn GICDevice,
) -> Result<()> {
KvmGICv3::init_device_attributes(vm, gic_device)?;
@ -115,7 +115,7 @@ pub mod kvm {
&its_fd,
kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
u64::from(kvm_bindings::KVM_VGIC_ITS_ADDR_TYPE),
&KvmGICv3ITS::get_msi_addr(u64::from(gic_device.vcpu_count())) as *const u64 as u64,
&KvmGICv3ITS::get_msi_addr(gic_device.vcpu_count()) as *const u64 as u64,
0,
)?;

View File

@ -136,13 +136,14 @@ pub fn arch_memory_regions(size: GuestUsize) -> Vec<(GuestAddress, usize, Region
///
/// * `guest_mem` - The memory to be used by the guest.
/// * `num_cpus` - Number of virtual CPUs the guest will have.
pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug>(
#[allow(clippy::too_many_arguments)]
pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug, S: ::std::hash::BuildHasher>(
vm: &Arc<dyn hypervisor::Vm>,
guest_mem: &GuestMemoryMmap,
cmdline_cstring: &CStr,
vcpu_count: u64,
vcpu_mpidr: Vec<u64>,
device_info: &HashMap<(DeviceType, String), T>,
device_info: &HashMap<(DeviceType, String), T, S>,
initrd: &Option<super::InitramfsConfig>,
pci_space_address: &Option<(u64, u64)>,
) -> super::Result<()> {
@ -157,7 +158,7 @@ pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug>(
cmdline_cstring,
vcpu_mpidr,
device_info,
&gic_device,
&*gic_device,
initrd,
pci_space_address,
)

View File

@ -52,7 +52,7 @@ const PSTATE_FAULT_BITS_64: u64 = PSR_MODE_EL1h | PSR_A_BIT | PSR_F_BIT | PSR_I_
// we're just doing pointer math on it, so in theory, it should safe.
macro_rules! offset__of {
($str:ty, $field:ident) => {
unsafe { &(*(0 as *const $str)).$field as *const _ as usize }
unsafe { &(*std::ptr::null::<user_pt_regs>()).$field as *const _ as usize }
};
}