mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 03:12:27 +00:00
arch: Fix AArch64 clippy warnings of arch crate
Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
parent
527e8e7b1d
commit
46b8f38987
@ -90,12 +90,12 @@ pub enum Error {
|
|||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
/// Creates the flattened device tree for this aarch64 VM.
|
/// 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,
|
guest_mem: &GuestMemoryMmap,
|
||||||
cmdline: &CStr,
|
cmdline: &CStr,
|
||||||
vcpu_mpidr: Vec<u64>,
|
vcpu_mpidr: Vec<u64>,
|
||||||
device_info: &HashMap<(DeviceType, String), T>,
|
device_info: &HashMap<(DeviceType, String), T, S>,
|
||||||
gic_device: &Box<dyn GICDevice>,
|
gic_device: &dyn GICDevice,
|
||||||
initrd: &Option<InitramfsConfig>,
|
initrd: &Option<InitramfsConfig>,
|
||||||
pci_space_address: &Option<(u64, u64)>,
|
pci_space_address: &Option<(u64, u64)>,
|
||||||
) -> Result<Vec<u8>> {
|
) -> 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.
|
// 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.
|
// See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml.
|
||||||
append_begin_node(fdt, "cpus")?;
|
append_begin_node(fdt, "cpus")?;
|
||||||
// As per documentation, on ARM v8 64-bit systems value should be set to 2.
|
// 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)?;
|
append_property_u32(fdt, "#size-cells", 0x0)?;
|
||||||
let num_cpus = vcpu_mpidr.len();
|
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);
|
let cpu_name = format!("cpu@{:x}", cpu_index);
|
||||||
append_begin_node(fdt, &cpu_name)?;
|
append_begin_node(fdt, &cpu_name)?;
|
||||||
append_property_string(fdt, "device_type", "cpu")?;
|
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.
|
// 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.
|
// 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)?;
|
||||||
}
|
}
|
||||||
append_end_node(fdt)?;
|
append_end_node(fdt)?;
|
||||||
@ -376,7 +376,7 @@ fn create_chosen_node(
|
|||||||
Ok(())
|
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());
|
let gic_reg_prop = generate_prop64(gic_device.device_properties());
|
||||||
|
|
||||||
append_begin_node(fdt, "intc")?;
|
append_begin_node(fdt, "intc")?;
|
||||||
@ -521,9 +521,9 @@ fn create_rtc_node<T: DeviceInfoForFDT + Clone + Debug>(
|
|||||||
Ok(())
|
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>,
|
fdt: &mut Vec<u8>,
|
||||||
dev_info: &HashMap<(DeviceType, String), T>,
|
dev_info: &HashMap<(DeviceType, String), T, S>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Create one temp Vec to store all virtio devices
|
// Create one temp Vec to store all virtio devices
|
||||||
let mut ordered_virtio_device: Vec<&T> = Vec::new();
|
let mut ordered_virtio_device: Vec<&T> = Vec::new();
|
||||||
|
@ -71,7 +71,7 @@ pub mod kvm {
|
|||||||
/// Setup the device-specific attributes
|
/// Setup the device-specific attributes
|
||||||
fn init_device_attributes(
|
fn init_device_attributes(
|
||||||
vm: &Arc<dyn hypervisor::Vm>,
|
vm: &Arc<dyn hypervisor::Vm>,
|
||||||
gic_device: &Box<dyn GICDevice>,
|
gic_device: &dyn GICDevice,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
/// Initialize a GIC device
|
/// Initialize a GIC device
|
||||||
@ -95,10 +95,10 @@ pub mod kvm {
|
|||||||
flags: u32,
|
flags: u32,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let attr = kvm_bindings::kvm_device_attr {
|
let attr = kvm_bindings::kvm_device_attr {
|
||||||
group: group,
|
group,
|
||||||
attr: attr,
|
attr,
|
||||||
addr: addr,
|
addr,
|
||||||
flags: flags,
|
flags,
|
||||||
};
|
};
|
||||||
device
|
device
|
||||||
.set_device_attr(&attr)
|
.set_device_attr(&attr)
|
||||||
@ -108,7 +108,7 @@ pub mod kvm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Finalize the setup of a GIC device
|
/// 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.
|
/* We need to tell the kernel how many irqs to support with this vgic.
|
||||||
* See the `layout` module for details.
|
* See the `layout` module for details.
|
||||||
*/
|
*/
|
||||||
@ -142,9 +142,9 @@ pub mod kvm {
|
|||||||
|
|
||||||
let device = Self::create_device(vgic_fd, vcpu_count);
|
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)
|
Ok(device)
|
||||||
}
|
}
|
||||||
|
@ -84,20 +84,20 @@ pub mod kvm {
|
|||||||
vcpu_count: u64,
|
vcpu_count: u64,
|
||||||
) -> Box<dyn GICDevice> {
|
) -> Box<dyn GICDevice> {
|
||||||
Box::new(KvmGICv2 {
|
Box::new(KvmGICv2 {
|
||||||
device: device,
|
device,
|
||||||
properties: [
|
properties: [
|
||||||
KvmGICv2::get_dist_addr(),
|
KvmGICv2::get_dist_addr(),
|
||||||
KvmGICv2::get_dist_size(),
|
KvmGICv2::get_dist_size(),
|
||||||
KvmGICv2::get_cpu_addr(),
|
KvmGICv2::get_cpu_addr(),
|
||||||
KvmGICv2::get_cpu_size(),
|
KvmGICv2::get_cpu_size(),
|
||||||
],
|
],
|
||||||
vcpu_count: vcpu_count,
|
vcpu_count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_device_attributes(
|
fn init_device_attributes(
|
||||||
_vm: &Arc<dyn hypervisor::Vm>,
|
_vm: &Arc<dyn hypervisor::Vm>,
|
||||||
gic_device: &Box<dyn GICDevice>,
|
gic_device: &dyn GICDevice,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
/* Setting up the distributor attribute.
|
/* Setting up the distributor attribute.
|
||||||
We are placing the GIC below 1GB so we need to substract the size of the distributor. */
|
We are placing the GIC below 1GB so we need to substract the size of the distributor. */
|
||||||
|
@ -84,20 +84,20 @@ pub mod kvm {
|
|||||||
vcpu_count: u64,
|
vcpu_count: u64,
|
||||||
) -> Box<dyn GICDevice> {
|
) -> Box<dyn GICDevice> {
|
||||||
Box::new(KvmGICv3 {
|
Box::new(KvmGICv3 {
|
||||||
device: device,
|
device,
|
||||||
properties: [
|
properties: [
|
||||||
KvmGICv3::get_dist_addr(),
|
KvmGICv3::get_dist_addr(),
|
||||||
KvmGICv3::get_dist_size(),
|
KvmGICv3::get_dist_size(),
|
||||||
KvmGICv3::get_redists_addr(vcpu_count),
|
KvmGICv3::get_redists_addr(vcpu_count),
|
||||||
KvmGICv3::get_redists_size(vcpu_count),
|
KvmGICv3::get_redists_size(vcpu_count),
|
||||||
],
|
],
|
||||||
vcpu_count: vcpu_count,
|
vcpu_count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_device_attributes(
|
fn init_device_attributes(
|
||||||
_vm: &Arc<dyn hypervisor::Vm>,
|
_vm: &Arc<dyn hypervisor::Vm>,
|
||||||
gic_device: &Box<dyn GICDevice>,
|
gic_device: &dyn GICDevice,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
/* Setting up the distributor attribute.
|
/* Setting up the distributor attribute.
|
||||||
We are placing the GIC below 1GB so we need to substract the size of the distributor.
|
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(),
|
gic_device.device(),
|
||||||
kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
|
kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
|
||||||
u64::from(kvm_bindings::KVM_VGIC_V3_ADDR_TYPE_REDIST),
|
u64::from(kvm_bindings::KVM_VGIC_V3_ADDR_TYPE_REDIST),
|
||||||
&KvmGICv3::get_redists_addr(u64::from(gic_device.vcpu_count())) as *const u64
|
&KvmGICv3::get_redists_addr(gic_device.vcpu_count()) as *const u64 as u64,
|
||||||
as u64,
|
|
||||||
0,
|
0,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ pub mod kvm {
|
|||||||
vcpu_count: u64,
|
vcpu_count: u64,
|
||||||
) -> Box<dyn GICDevice> {
|
) -> Box<dyn GICDevice> {
|
||||||
Box::new(KvmGICv3ITS {
|
Box::new(KvmGICv3ITS {
|
||||||
device: device,
|
device,
|
||||||
gic_properties: [
|
gic_properties: [
|
||||||
KvmGICv3::get_dist_addr(),
|
KvmGICv3::get_dist_addr(),
|
||||||
KvmGICv3::get_dist_size(),
|
KvmGICv3::get_dist_size(),
|
||||||
@ -91,13 +91,13 @@ pub mod kvm {
|
|||||||
KvmGICv3ITS::get_msi_addr(vcpu_count),
|
KvmGICv3ITS::get_msi_addr(vcpu_count),
|
||||||
KvmGICv3ITS::get_msi_size(),
|
KvmGICv3ITS::get_msi_size(),
|
||||||
],
|
],
|
||||||
vcpu_count: vcpu_count,
|
vcpu_count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_device_attributes(
|
fn init_device_attributes(
|
||||||
vm: &Arc<dyn hypervisor::Vm>,
|
vm: &Arc<dyn hypervisor::Vm>,
|
||||||
gic_device: &Box<dyn GICDevice>,
|
gic_device: &dyn GICDevice,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
KvmGICv3::init_device_attributes(vm, gic_device)?;
|
KvmGICv3::init_device_attributes(vm, gic_device)?;
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ pub mod kvm {
|
|||||||
&its_fd,
|
&its_fd,
|
||||||
kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
|
kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR,
|
||||||
u64::from(kvm_bindings::KVM_VGIC_ITS_ADDR_TYPE),
|
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,
|
0,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -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.
|
/// * `guest_mem` - The memory to be used by the guest.
|
||||||
/// * `num_cpus` - Number of virtual CPUs the guest will have.
|
/// * `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>,
|
vm: &Arc<dyn hypervisor::Vm>,
|
||||||
guest_mem: &GuestMemoryMmap,
|
guest_mem: &GuestMemoryMmap,
|
||||||
cmdline_cstring: &CStr,
|
cmdline_cstring: &CStr,
|
||||||
vcpu_count: u64,
|
vcpu_count: u64,
|
||||||
vcpu_mpidr: Vec<u64>,
|
vcpu_mpidr: Vec<u64>,
|
||||||
device_info: &HashMap<(DeviceType, String), T>,
|
device_info: &HashMap<(DeviceType, String), T, S>,
|
||||||
initrd: &Option<super::InitramfsConfig>,
|
initrd: &Option<super::InitramfsConfig>,
|
||||||
pci_space_address: &Option<(u64, u64)>,
|
pci_space_address: &Option<(u64, u64)>,
|
||||||
) -> super::Result<()> {
|
) -> super::Result<()> {
|
||||||
@ -157,7 +158,7 @@ pub fn configure_system<T: DeviceInfoForFDT + Clone + Debug>(
|
|||||||
cmdline_cstring,
|
cmdline_cstring,
|
||||||
vcpu_mpidr,
|
vcpu_mpidr,
|
||||||
device_info,
|
device_info,
|
||||||
&gic_device,
|
&*gic_device,
|
||||||
initrd,
|
initrd,
|
||||||
pci_space_address,
|
pci_space_address,
|
||||||
)
|
)
|
||||||
|
@ -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.
|
// we're just doing pointer math on it, so in theory, it should safe.
|
||||||
macro_rules! offset__of {
|
macro_rules! offset__of {
|
||||||
($str:ty, $field:ident) => {
|
($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 }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user