Skip to content

Commit ae7c0dd

Browse files
htonkovaclikebreath
authored andcommitted
build: exempt arch from clippy::absolute_paths, use full paths
Suggested by phip1611 on cloud-hypervisor#8446. This adds the repo's first clippy.toml, carving arch out of the absolute_paths deny from cloud-hypervisor#7670. Glob imports and trait imports that must be in scope for method-call resolution (e.g. DeviceInfoForFdt for .irq()) are left as-is. Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com> Assisted-by: Claude:Opus-4.8
1 parent a8a3a59 commit ae7c0dd

7 files changed

Lines changed: 51 additions & 65 deletions

File tree

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
absolute-paths-allowed-crates = ["arch"]

devices/src/legacy/fw_cfg.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use std::{
2424
use acpi_tables::rsdp::Rsdp;
2525
use arch::RegionType;
2626
#[cfg(target_arch = "aarch64")]
27-
use arch::aarch64::arch_memory_regions;
28-
#[cfg(target_arch = "aarch64")]
2927
use arch::aarch64::layout::{
3028
MEM_32BIT_DEVICES_START, MEM_32BIT_RESERVED_START, RAM_64BIT_START, RAM_START as HIGH_RAM_START,
3129
};
@@ -487,7 +485,7 @@ impl FwCfg {
487485
(STAGE0_START_ADDRESS, STAGE0_SIZE, RegionType::Reserved),
488486
];
489487
#[cfg(target_arch = "aarch64")]
490-
let mut mem_regions = arch_memory_regions();
488+
let mut mem_regions = arch::aarch64::arch_memory_regions();
491489
if mem_size < MEM_32BIT_DEVICES_START.0 as usize {
492490
mem_regions.push((
493491
HIGH_RAM_START,

vmm/src/acpi.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use acpi_tables::sdt::Sdt;
1313
use arch::DeviceType;
1414
#[cfg(target_arch = "aarch64")]
1515
use arch::aarch64::DeviceInfoForFdt;
16-
#[cfg(target_arch = "x86_64")]
17-
use arch::x86_64;
1816
use arch::{NumaNodes, layout};
1917
use bitflags::bitflags;
2018
use log::{info, warn};
@@ -399,7 +397,7 @@ fn create_srat_table(
399397

400398
for cpu in &node.cpus {
401399
#[cfg(target_arch = "x86_64")]
402-
let x2apic_id = x86_64::get_x2apic_id(*cpu, topology);
400+
let x2apic_id = arch::x86_64::get_x2apic_id(*cpu, topology);
403401
#[cfg(target_arch = "aarch64")]
404402
let x2apic_id = *cpu;
405403

vmm/src/cpu.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ use std::{any, cmp, hint, io, panic, result, thread, time};
2323
use acpi_tables::sdt::Sdt;
2424
use acpi_tables::{Aml, aml};
2525
use anyhow::anyhow;
26-
#[cfg(target_arch = "x86_64")]
27-
use arch::x86_64;
28-
#[cfg(target_arch = "x86_64")]
29-
use arch::x86_64::get_x2apic_id;
3026
use arch::{EntryPoint, NumaNodes, layout};
3127
#[cfg(target_arch = "aarch64")]
3228
use devices::gic::Gic;
@@ -988,7 +984,7 @@ impl CpuManager {
988984
#[cfg(target_arch = "x86_64")]
989985
let topology = self.get_vcpu_topology();
990986
#[cfg(target_arch = "x86_64")]
991-
let x2apic_id = x86_64::get_x2apic_id(cpu_id, topology);
987+
let x2apic_id = arch::x86_64::get_x2apic_id(cpu_id, topology);
992988
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
993989
let x2apic_id = cpu_id;
994990

@@ -1762,7 +1758,7 @@ impl CpuManager {
17621758
madt.write(36, layout::APIC_START.0);
17631759

17641760
for cpu in 0..self.config.max_vcpus {
1765-
let x2apic_id = get_x2apic_id(cpu, self.get_vcpu_topology());
1761+
let x2apic_id = arch::x86_64::get_x2apic_id(cpu, self.get_vcpu_topology());
17661762

17671763
let lapic = LocalX2Apic {
17681764
r#type: acpi::ACPI_X2APIC_PROCESSOR,
@@ -2327,7 +2323,7 @@ const MADT_CPU_ONLINE_CAPABLE_FLAG: usize = 1;
23272323
impl Cpu {
23282324
#[cfg(target_arch = "x86_64")]
23292325
fn generate_mat(&self) -> Vec<u8> {
2330-
let x2apic_id = x86_64::get_x2apic_id(self.cpu_id, self.topology);
2326+
let x2apic_id = arch::x86_64::get_x2apic_id(self.cpu_id, self.topology);
23312327

23322328
LocalX2Apic {
23332329
r#type: acpi::ACPI_X2APIC_PROCESSOR,

vmm/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ use anyhow::{Context, anyhow};
2222
#[cfg(feature = "dbus_api")]
2323
use api::dbus::{DBusApiOptions, DBusApiShutdownChannels};
2424
use api::http::HttpApiHandle;
25-
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
26-
use arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY;
2725
use console_devices::{ConsoleInfo, pre_create_console_devices};
2826
use event_monitor::event;
2927
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
@@ -1224,7 +1222,7 @@ impl Vmm {
12241222
})?;
12251223

12261224
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
1227-
if config.lock().unwrap().max_apic_id() > MAX_SUPPORTED_CPUS_LEGACY {
1225+
if config.lock().unwrap().max_apic_id() > arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY {
12281226
vm.enable_x2apic_api().unwrap();
12291227
}
12301228

vmm/src/vm.rs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,10 @@ use std::{any, cmp, result, str, thread};
2727
use anyhow::{Context, anyhow};
2828
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
2929
use arch::PciSpaceInfo;
30-
#[cfg(not(target_arch = "x86_64"))]
31-
use arch::aarch64;
3230
#[cfg(target_arch = "x86_64")]
3331
use arch::layout::{KVM_IDENTITY_MAP_START, KVM_TSS_START};
3432
#[cfg(not(target_arch = "x86_64"))]
3533
use arch::uefi;
36-
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
37-
use arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY;
38-
#[cfg(feature = "tdx")]
39-
use arch::x86_64::tdx;
40-
#[cfg(feature = "tdx")]
41-
use arch::x86_64::tdx::TdvfSection;
4234
use arch::{EntryPoint, NumaNode, NumaNodes, get_host_cpu_phys_bits, layout};
4335
use devices::AcpiNotificationFlags;
4436
#[cfg(target_arch = "aarch64")]
@@ -145,7 +137,7 @@ pub enum Error {
145137

146138
#[cfg(target_arch = "aarch64")]
147139
#[error("Cannot load the UEFI binary in memory")]
148-
UefiLoad(#[source] aarch64::uefi::Error),
140+
UefiLoad(#[source] arch::aarch64::uefi::Error),
149141

150142
#[cfg(target_arch = "riscv64")]
151143
#[error("Cannot load the UEFI binary in memory")]
@@ -313,11 +305,11 @@ pub enum Error {
313305

314306
#[cfg(feature = "tdx")]
315307
#[error("Error parsing TDVF")]
316-
ParseTdvf(#[source] tdx::TdvfError),
308+
ParseTdvf(#[source] arch::x86_64::tdx::TdvfError),
317309

318310
#[cfg(feature = "tdx")]
319311
#[error("Error populating TDX HOB")]
320-
PopulateHob(#[source] tdx::TdvfError),
312+
PopulateHob(#[source] arch::x86_64::tdx::TdvfError),
321313

322314
#[cfg(feature = "tdx")]
323315
#[error("Error allocating TDVF memory")]
@@ -1402,7 +1394,7 @@ impl Vm {
14021394
};
14031395

14041396
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
1405-
if vm_config.lock().unwrap().max_apic_id() > MAX_SUPPORTED_CPUS_LEGACY {
1397+
if vm_config.lock().unwrap().max_apic_id() > arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY {
14061398
vm.enable_x2apic_api().unwrap();
14071399
}
14081400

@@ -1919,7 +1911,9 @@ impl Vm {
19191911
.unwrap()
19201912
.get_vgic()
19211913
.map_err(|_| {
1922-
Error::ConfigureSystem(arch::Error::PlatformSpecific(aarch64::Error::SetupGic))
1914+
Error::ConfigureSystem(arch::Error::PlatformSpecific(
1915+
arch::aarch64::Error::SetupGic,
1916+
))
19231917
})?;
19241918

19251919
// PMU interrupt sticks to PPI, so need to be added by 16 to get real irq number.
@@ -1929,7 +1923,9 @@ impl Vm {
19291923
.unwrap()
19301924
.init_pmu(AARCH64_PMU_IRQ + 16)
19311925
.map_err(|_| {
1932-
Error::ConfigureSystem(arch::Error::PlatformSpecific(aarch64::Error::VcpuInitPmu))
1926+
Error::ConfigureSystem(arch::Error::PlatformSpecific(
1927+
arch::aarch64::Error::VcpuInitPmu,
1928+
))
19331929
})?;
19341930

19351931
arch::configure_system(
@@ -2425,7 +2421,7 @@ impl Vm {
24252421
}
24262422

24272423
#[cfg(feature = "tdx")]
2428-
fn extract_tdvf_sections(&mut self) -> Result<(Vec<TdvfSection>, bool)> {
2424+
fn extract_tdvf_sections(&mut self) -> Result<(Vec<arch::x86_64::tdx::TdvfSection>, bool)> {
24292425
use arch::x86_64::tdx::*;
24302426

24312427
let firmware_path = self
@@ -2447,7 +2443,7 @@ impl Vm {
24472443

24482444
#[cfg(feature = "tdx")]
24492445
fn hob_memory_resources(
2450-
mut sorted_sections: Vec<TdvfSection>,
2446+
mut sorted_sections: Vec<arch::x86_64::tdx::TdvfSection>,
24512447
guest_memory: &GuestMemoryMmap,
24522448
) -> Vec<(u64, u64, bool)> {
24532449
let mut list = Vec::new();
@@ -2508,7 +2504,7 @@ impl Vm {
25082504
#[cfg(feature = "tdx")]
25092505
fn populate_tdx_sections(
25102506
&mut self,
2511-
sections: &[TdvfSection],
2507+
sections: &[arch::x86_64::tdx::TdvfSection],
25122508
guid_found: bool,
25132509
) -> Result<Option<u64>> {
25142510
use arch::x86_64::tdx::*;
@@ -2694,7 +2690,7 @@ impl Vm {
26942690
}
26952691

26962692
#[cfg(feature = "tdx")]
2697-
fn init_tdx_memory(&mut self, sections: &[TdvfSection]) -> Result<()> {
2693+
fn init_tdx_memory(&mut self, sections: &[arch::x86_64::tdx::TdvfSection]) -> Result<()> {
26982694
let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory();
26992695
let mem = guest_memory.memory();
27002696

@@ -3703,12 +3699,12 @@ mod unit_tests {
37033699
fn test_hob_memory_resources() {
37043700
// Case 1: Two TDVF sections in the middle of the RAM
37053701
let sections = vec![
3706-
TdvfSection {
3702+
arch::x86_64::tdx::TdvfSection {
37073703
address: 0xc000,
37083704
size: 0x1000,
37093705
..Default::default()
37103706
},
3711-
TdvfSection {
3707+
arch::x86_64::tdx::TdvfSection {
37123708
address: 0x1000,
37133709
size: 0x4000,
37143710
..Default::default()
@@ -3732,12 +3728,12 @@ mod unit_tests {
37323728

37333729
// Case 2: Two TDVF sections with no conflict with the RAM
37343730
let sections = vec![
3735-
TdvfSection {
3731+
arch::x86_64::tdx::TdvfSection {
37363732
address: 0x1000_1000,
37373733
size: 0x1000,
37383734
..Default::default()
37393735
},
3740-
TdvfSection {
3736+
arch::x86_64::tdx::TdvfSection {
37413737
address: 0,
37423738
size: 0x1000,
37433739
..Default::default()
@@ -3759,12 +3755,12 @@ mod unit_tests {
37593755

37603756
// Case 3: Two TDVF sections with partial conflicts with the RAM
37613757
let sections = vec![
3762-
TdvfSection {
3758+
arch::x86_64::tdx::TdvfSection {
37633759
address: 0x1000_0000,
37643760
size: 0x2000,
37653761
..Default::default()
37663762
},
3767-
TdvfSection {
3763+
arch::x86_64::tdx::TdvfSection {
37683764
address: 0,
37693765
size: 0x2000,
37703766
..Default::default()
@@ -3787,22 +3783,22 @@ mod unit_tests {
37873783
// Case 4: Two TDVF sections with no conflict before the RAM and two
37883784
// more additional sections with no conflict after the RAM.
37893785
let sections = vec![
3790-
TdvfSection {
3786+
arch::x86_64::tdx::TdvfSection {
37913787
address: 0x2000_1000,
37923788
size: 0x1000,
37933789
..Default::default()
37943790
},
3795-
TdvfSection {
3791+
arch::x86_64::tdx::TdvfSection {
37963792
address: 0x2000_0000,
37973793
size: 0x1000,
37983794
..Default::default()
37993795
},
3800-
TdvfSection {
3796+
arch::x86_64::tdx::TdvfSection {
38013797
address: 0x1000,
38023798
size: 0x1000,
38033799
..Default::default()
38043800
},
3805-
TdvfSection {
3801+
arch::x86_64::tdx::TdvfSection {
38063802
address: 0,
38073803
size: 0x1000,
38083804
..Default::default()
@@ -3825,7 +3821,7 @@ mod unit_tests {
38253821
);
38263822

38273823
// Case 5: One TDVF section overriding the entire RAM
3828-
let sections = vec![TdvfSection {
3824+
let sections = vec![arch::x86_64::tdx::TdvfSection {
38293825
address: 0,
38303826
size: 0x2000_0000,
38313827
..Default::default()
@@ -3842,12 +3838,12 @@ mod unit_tests {
38423838

38433839
// Case 6: Two TDVF sections with no conflict with 2 RAM regions
38443840
let sections = vec![
3845-
TdvfSection {
3841+
arch::x86_64::tdx::TdvfSection {
38463842
address: 0x1000_2000,
38473843
size: 0x2000,
38483844
..Default::default()
38493845
},
3850-
TdvfSection {
3846+
arch::x86_64::tdx::TdvfSection {
38513847
address: 0,
38523848
size: 0x2000,
38533849
..Default::default()
@@ -3873,12 +3869,12 @@ mod unit_tests {
38733869

38743870
// Case 7: Two TDVF sections with partial conflicts with 2 RAM regions
38753871
let sections = vec![
3876-
TdvfSection {
3872+
arch::x86_64::tdx::TdvfSection {
38773873
address: 0x1000_0000,
38783874
size: 0x4000,
38793875
..Default::default()
38803876
},
3881-
TdvfSection {
3877+
arch::x86_64::tdx::TdvfSection {
38823878
address: 0,
38833879
size: 0x4000,
38843880
..Default::default()
@@ -3974,8 +3970,6 @@ mod unit_tests {
39743970
#[cfg(target_arch = "aarch64")]
39753971
#[cfg(test)]
39763972
mod unit_tests {
3977-
use arch::aarch64::fdt::create_fdt;
3978-
use arch::aarch64::layout;
39793973
use arch::{DeviceType, MmioDeviceInfo};
39803974
use devices::gic::Gic;
39813975

@@ -3985,7 +3979,10 @@ mod unit_tests {
39853979

39863980
#[test]
39873981
fn test_create_fdt_with_devices() {
3988-
let regions = vec![(layout::RAM_START, (layout::FDT_MAX_SIZE + 0x1000) as usize)];
3982+
let regions = vec![(
3983+
arch::aarch64::layout::RAM_START,
3984+
(arch::aarch64::layout::FDT_MAX_SIZE + 0x1000) as usize,
3985+
)];
39893986
let mem = GuestMemoryMmap::from_ranges(&regions).expect("Cannot initialize memory");
39903987

39913988
let dev_info: HashMap<(DeviceType, String), MmioDeviceInfo> = [
@@ -4022,7 +4019,7 @@ mod unit_tests {
40224019
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
40234020
let vgic_config = Gic::create_default_config(1);
40244021
let gic = vm.create_vgic(&vgic_config).expect("Cannot create gic");
4025-
create_fdt(
4022+
arch::aarch64::fdt::create_fdt(
40264023
&mem,
40274024
"console=tty0",
40284025
&[0],

0 commit comments

Comments
 (0)