diff --git a/.rustfmt.toml b/.rustfmt.toml index b2477a2f6..754d7badf 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,4 @@ edition = "2021" group_imports="StdExternalCrate" +imports_granularity="Module" + diff --git a/arch/src/aarch64/fdt.rs b/arch/src/aarch64/fdt.rs index c96ba1365..4d6f49d7b 100644 --- a/arch/src/aarch64/fdt.rs +++ b/arch/src/aarch64/fdt.rs @@ -6,15 +6,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the THIRD-PARTY file. -use std::cmp; use std::collections::HashMap; use std::ffi::CStr; use std::fmt::Debug; -use std::fs; use std::path::Path; -use std::result; -use std::str; use std::sync::{Arc, Mutex}; +use std::{cmp, fs, result, str}; use byteorder::{BigEndian, ByteOrder}; use hypervisor::arch::aarch64::gic::Vgic; @@ -22,9 +19,7 @@ use thiserror::Error; use vm_fdt::{FdtWriter, FdtWriterResult}; use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryRegion}; -use super::super::DeviceType; -use super::super::GuestMemoryMmap; -use super::super::InitramfsConfig; +use super::super::{DeviceType, GuestMemoryMmap, InitramfsConfig}; use super::layout::{ IRQ_BASE, MEM_32BIT_DEVICES_SIZE, MEM_32BIT_DEVICES_START, MEM_PCI_IO_SIZE, MEM_PCI_IO_START, PCI_HIGH_BASE, PCI_MMIO_CONFIG_SIZE_PER_SEGMENT, diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 6dab02116..6cbe44573 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -11,9 +11,8 @@ extern crate log; use std::collections::BTreeMap; -use std::fmt; -use std::result; use std::sync::Arc; +use std::{fmt, result}; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index 8090f50b4..670bf9ac6 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -27,9 +27,7 @@ use vm_memory::{ GuestMemoryRegion, GuestUsize, }; -use crate::GuestMemoryMmap; -use crate::InitramfsConfig; -use crate::RegionType; +use crate::{GuestMemoryMmap, InitramfsConfig, RegionType}; mod smbios; use std::arch::x86_64; #[cfg(feature = "tdx")] diff --git a/arch/src/x86_64/mptable.rs b/arch/src/x86_64/mptable.rs index 7ed48d287..99651be60 100644 --- a/arch/src/x86_64/mptable.rs +++ b/arch/src/x86_64/mptable.rs @@ -5,9 +5,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-BSD-3-Clause file. -use std::mem; -use std::result; -use std::slice; +use std::{mem, result, slice}; use libc::c_uchar; use thiserror::Error; @@ -306,9 +304,8 @@ pub fn setup_mptable( #[cfg(test)] mod tests { - use vm_memory::{ - bitmap::BitmapSlice, GuestUsize, VolatileMemoryError, VolatileSlice, WriteVolatile, - }; + use vm_memory::bitmap::BitmapSlice; + use vm_memory::{GuestUsize, VolatileMemoryError, VolatileSlice, WriteVolatile}; use super::*; use crate::layout::MPTABLE_START; diff --git a/arch/src/x86_64/smbios.rs b/arch/src/x86_64/smbios.rs index bc56b02a3..367e89237 100644 --- a/arch/src/x86_64/smbios.rs +++ b/arch/src/x86_64/smbios.rs @@ -6,14 +6,11 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause -use std::mem; -use std::result; -use std::slice; +use std::{mem, result, slice}; use thiserror::Error; use uuid::Uuid; -use vm_memory::ByteValued; -use vm_memory::{Address, Bytes, GuestAddress}; +use vm_memory::{Address, ByteValued, Bytes, GuestAddress}; use crate::layout::SMBIOS_START; use crate::GuestMemoryMmap; diff --git a/block/src/lib.rs b/block/src/lib.rs index b7904caf5..3b6d721c4 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -31,7 +31,6 @@ pub mod vhdx; pub mod vhdx_sync; use std::alloc::{alloc_zeroed, dealloc, Layout}; -use std::cmp; use std::collections::VecDeque; use std::fmt::Debug; use std::fs::File; @@ -39,10 +38,9 @@ use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write}; use std::os::linux::fs::MetadataExt; use std::os::unix::io::AsRawFd; use std::path::Path; -use std::result; -use std::sync::Arc; -use std::sync::MutexGuard; +use std::sync::{Arc, MutexGuard}; use std::time::Instant; +use std::{cmp, result}; #[cfg(feature = "io_uring")] use io_uring::{opcode, IoUring, Probe}; @@ -52,14 +50,13 @@ use smallvec::SmallVec; use thiserror::Error; use virtio_bindings::virtio_blk::*; use virtio_queue::DescriptorChain; +use vm_memory::bitmap::Bitmap; use vm_memory::{ - bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, - GuestMemoryLoadGuard, + ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryLoadGuard, }; use vm_virtio::{AccessPlatform, Translatable}; -use vmm_sys_util::aio; use vmm_sys_util::eventfd::EventFd; -use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr}; +use vmm_sys_util::{aio, ioctl_io_nr, ioctl_ioc_nr}; use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult}; use crate::fixed_vhd::FixedVhd; diff --git a/block/src/qcow/mod.rs b/block/src/qcow/mod.rs index a4f0c98a4..44ef478c9 100644 --- a/block/src/qcow/mod.rs +++ b/block/src/qcow/mod.rs @@ -19,17 +19,14 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use libc::{EINVAL, ENOSPC, ENOTSUP}; use remain::sorted; use thiserror::Error; -use vmm_sys_util::{ - file_traits::FileSetLen, file_traits::FileSync, seek_hole::SeekHole, write_zeroes::PunchHole, - write_zeroes::WriteZeroesAt, -}; +use vmm_sys_util::file_traits::{FileSetLen, FileSync}; +use vmm_sys_util::seek_hole::SeekHole; +use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt}; +use crate::qcow::qcow_raw_file::QcowRawFile; pub use crate::qcow::raw_file::RawFile; -use crate::qcow::{ - qcow_raw_file::QcowRawFile, - refcount::RefCount, - vec_cache::{CacheMap, Cacheable, VecCache}, -}; +use crate::qcow::refcount::RefCount; +use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache}; use crate::BlockBackend; /// Nesting depth limit for disk formats that can open other disk files. diff --git a/block/src/qcow/raw_file.rs b/block/src/qcow/raw_file.rs index 0fa5acd43..46abcc904 100644 --- a/block/src/qcow/raw_file.rs +++ b/block/src/qcow/raw_file.rs @@ -15,7 +15,8 @@ use std::os::unix::io::{AsRawFd, RawFd}; use std::slice; use libc::c_void; -use vmm_sys_util::{seek_hole::SeekHole, write_zeroes::PunchHole, write_zeroes::WriteZeroesAt}; +use vmm_sys_util::seek_hole::SeekHole; +use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt}; use crate::BlockBackend; diff --git a/block/src/qcow/refcount.rs b/block/src/qcow/refcount.rs index 8e496ff7e..33bf5c045 100644 --- a/block/src/qcow/refcount.rs +++ b/block/src/qcow/refcount.rs @@ -9,10 +9,8 @@ use std::io; use libc::EINVAL; use thiserror::Error; -use crate::qcow::{ - qcow_raw_file::QcowRawFile, - vec_cache::{CacheMap, Cacheable, VecCache}, -}; +use crate::qcow::qcow_raw_file::QcowRawFile; +use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache}; #[derive(Debug, Error)] pub enum Error { diff --git a/block/src/vhdx/mod.rs b/block/src/vhdx/mod.rs index 53e79218e..187d76c03 100644 --- a/block/src/vhdx/mod.rs +++ b/block/src/vhdx/mod.rs @@ -11,12 +11,10 @@ use remain::sorted; use thiserror::Error; use uuid::Uuid; -use crate::vhdx::{ - vhdx_bat::{BatEntry, VhdxBatError}, - vhdx_header::{RegionInfo, RegionTableEntry, VhdxHeader, VhdxHeaderError}, - vhdx_io::VhdxIoError, - vhdx_metadata::{DiskSpec, VhdxMetadataError}, -}; +use crate::vhdx::vhdx_bat::{BatEntry, VhdxBatError}; +use crate::vhdx::vhdx_header::{RegionInfo, RegionTableEntry, VhdxHeader, VhdxHeaderError}; +use crate::vhdx::vhdx_io::VhdxIoError; +use crate::vhdx::vhdx_metadata::{DiskSpec, VhdxMetadataError}; use crate::BlockBackend; macro_rules! div_round_up { diff --git a/block/src/vhdx/vhdx_bat.rs b/block/src/vhdx/vhdx_bat.rs index 314adab7e..e86eda4b1 100644 --- a/block/src/vhdx/vhdx_bat.rs +++ b/block/src/vhdx/vhdx_bat.rs @@ -10,7 +10,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use remain::sorted; use thiserror::Error; -use crate::vhdx::{vhdx_header::RegionTableEntry, vhdx_metadata::DiskSpec}; +use crate::vhdx::vhdx_header::RegionTableEntry; +use crate::vhdx::vhdx_metadata::DiskSpec; // Payload BAT Entry States pub const PAYLOAD_BLOCK_NOT_PRESENT: u64 = 0; diff --git a/block/src/vhdx/vhdx_io.rs b/block/src/vhdx/vhdx_io.rs index edb83a844..c2aed7fcb 100644 --- a/block/src/vhdx/vhdx_io.rs +++ b/block/src/vhdx/vhdx_io.rs @@ -8,10 +8,8 @@ use std::io::{self, Read, Seek, SeekFrom, Write}; use remain::sorted; use thiserror::Error; -use crate::vhdx::{ - vhdx_bat::{self, BatEntry, VhdxBatError}, - vhdx_metadata::{self, DiskSpec}, -}; +use crate::vhdx::vhdx_bat::{self, BatEntry, VhdxBatError}; +use crate::vhdx::vhdx_metadata::{self, DiskSpec}; const SECTOR_SIZE: u64 = 512; diff --git a/devices/src/gic.rs b/devices/src/gic.rs index 1f9d23998..d6ea1a12d 100644 --- a/devices/src/gic.rs +++ b/devices/src/gic.rs @@ -9,10 +9,8 @@ use std::sync::{Arc, Mutex}; use anyhow::anyhow; use arch::layout; -use hypervisor::{ - arch::aarch64::gic::{Vgic, VgicConfig}, - CpuState, GicState, -}; +use hypervisor::arch::aarch64::gic::{Vgic, VgicConfig}; +use hypervisor::{CpuState, GicState}; use vm_device::interrupt::{ InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup, LegacyIrqSourceConfig, MsiIrqGroupConfig, diff --git a/devices/src/interrupt_controller.rs b/devices/src/interrupt_controller.rs index 40f842d7d..f2deeb9de 100644 --- a/devices/src/interrupt_controller.rs +++ b/devices/src/interrupt_controller.rs @@ -2,8 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause -use std::io; -use std::result; +use std::{io, result}; use thiserror::Error; use vmm_sys_util::eventfd::EventFd; diff --git a/devices/src/legacy/cmos.rs b/devices/src/legacy/cmos.rs index 5f167698a..492e832fb 100644 --- a/devices/src/legacy/cmos.rs +++ b/devices/src/legacy/cmos.rs @@ -5,10 +5,9 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause use std::cmp::min; -use std::mem; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier}; -use std::thread; +use std::{mem, thread}; // https://github.com/rust-lang/libc/issues/1848 #[cfg_attr(target_env = "musl", allow(deprecated))] diff --git a/devices/src/legacy/gpio_pl061.rs b/devices/src/legacy/gpio_pl061.rs index 5f4a3fc0f..e69cb62a5 100644 --- a/devices/src/legacy/gpio_pl061.rs +++ b/devices/src/legacy/gpio_pl061.rs @@ -7,9 +7,8 @@ //! This module implements an ARM PrimeCell General Purpose Input/Output(PL061) to support gracefully poweroff microvm from external. //! -use std::io; -use std::result; use std::sync::{Arc, Barrier}; +use std::{io, result}; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/devices/src/legacy/i8042.rs b/devices/src/legacy/i8042.rs index b241ce2de..cc4bcd3e6 100644 --- a/devices/src/legacy/i8042.rs +++ b/devices/src/legacy/i8042.rs @@ -4,10 +4,8 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, Barrier, -}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Barrier}; use std::thread; use vm_device::BusDevice; diff --git a/devices/src/pvmemcontrol.rs b/devices/src/pvmemcontrol.rs index 5b95010f5..5721ed65e 100644 --- a/devices/src/pvmemcontrol.rs +++ b/devices/src/pvmemcontrol.rs @@ -3,12 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::{ - collections::HashMap, - ffi::CString, - io, result, - sync::{Arc, Barrier, Mutex, RwLock}, -}; +use std::collections::HashMap; +use std::ffi::CString; +use std::sync::{Arc, Barrier, Mutex, RwLock}; +use std::{io, result}; use num_enum::TryFromPrimitive; use pci::{ @@ -16,11 +14,13 @@ use pci::{ PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, }; use thiserror::Error; -use vm_allocator::{page_size::get_page_size, AddressAllocator, SystemAllocator}; +use vm_allocator::page_size::get_page_size; +use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_device::{BusDeviceSync, Resource}; +use vm_memory::bitmap::AtomicBitmap; use vm_memory::{ - bitmap::AtomicBitmap, Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, - GuestMemoryAtomic, GuestMemoryError, GuestMemoryMmap, Le32, Le64, + Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, + GuestMemoryError, GuestMemoryMmap, Le32, Le64, }; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; diff --git a/fuzz/fuzz_targets/balloon.rs b/fuzz/fuzz_targets/balloon.rs index ec97149bd..4870b538b 100644 --- a/fuzz/fuzz_targets/balloon.rs +++ b/fuzz/fuzz_targets/balloon.rs @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/block.rs b/fuzz/fuzz_targets/block.rs index 01d774e8f..3cc8d1eaa 100644 --- a/fuzz/fuzz_targets/block.rs +++ b/fuzz/fuzz_targets/block.rs @@ -9,19 +9,20 @@ #![no_main] use std::collections::BTreeMap; -use std::ffi; use std::fs::File; -use std::io; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::PathBuf; use std::sync::Arc; +use std::{ffi, io}; -use block::{async_io::DiskFile, raw_sync::RawFileDiskSync}; +use block::async_io::DiskFile; +use block::raw_sync::RawFileDiskSync; use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/console.rs b/fuzz/fuzz_targets/console.rs index 58d20c224..83f766b0b 100644 --- a/fuzz/fuzz_targets/console.rs +++ b/fuzz/fuzz_targets/console.rs @@ -13,7 +13,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/http_api.rs b/fuzz/fuzz_targets/http_api.rs index 5a6eefdc5..c9d2559fd 100644 --- a/fuzz/fuzz_targets/http_api.rs +++ b/fuzz/fuzz_targets/http_api.rs @@ -12,9 +12,10 @@ use libfuzzer_sys::fuzz_target; use micro_http::Request; use once_cell::sync::Lazy; use vm_migration::MigratableError; +use vmm::api::http::*; use vmm::api::{ - http::*, ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData, - VmSendMigrationData, VmmPingResponse, + ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData, VmSendMigrationData, + VmmPingResponse, }; use vmm::config::RestoreConfig; use vmm::vm::{Error as VmError, VmState}; diff --git a/fuzz/fuzz_targets/iommu.rs b/fuzz/fuzz_targets/iommu.rs index 8f02b420b..f0c4c8c7e 100644 --- a/fuzz/fuzz_targets/iommu.rs +++ b/fuzz/fuzz_targets/iommu.rs @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/linux_loader.rs b/fuzz/fuzz_targets/linux_loader.rs index fd6c09d66..937221536 100644 --- a/fuzz/fuzz_targets/linux_loader.rs +++ b/fuzz/fuzz_targets/linux_loader.rs @@ -8,15 +8,15 @@ #![no_main] -use std::ffi; use std::fs::File; -use std::io; use std::io::{Seek, SeekFrom, Write}; use std::os::unix::io::{FromRawFd, RawFd}; +use std::{ffi, io}; use libfuzzer_sys::fuzz_target; use linux_loader::loader::KernelLoader; -use vm_memory::{bitmap::AtomicBitmap, GuestAddress}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::GuestAddress; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/linux_loader_cmdline.rs b/fuzz/fuzz_targets/linux_loader_cmdline.rs index 747adf6f4..7c45a4287 100644 --- a/fuzz/fuzz_targets/linux_loader_cmdline.rs +++ b/fuzz/fuzz_targets/linux_loader_cmdline.rs @@ -9,7 +9,8 @@ #![no_main] use libfuzzer_sys::fuzz_target; -use vm_memory::{bitmap::AtomicBitmap, GuestAddress}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::GuestAddress; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/mem.rs b/fuzz/fuzz_targets/mem.rs index e0204e41e..8dde950bc 100644 --- a/fuzz/fuzz_targets/mem.rs +++ b/fuzz/fuzz_targets/mem.rs @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{BlocksState, Mem, VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/net.rs b/fuzz/fuzz_targets/net.rs index 3469e2f28..45604362f 100644 --- a/fuzz/fuzz_targets/net.rs +++ b/fuzz/fuzz_targets/net.rs @@ -13,7 +13,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm::EpollContext; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; diff --git a/fuzz/fuzz_targets/pmem.rs b/fuzz/fuzz_targets/pmem.rs index 786ad30ec..d0b165a7b 100644 --- a/fuzz/fuzz_targets/pmem.rs +++ b/fuzz/fuzz_targets/pmem.rs @@ -4,19 +4,19 @@ #![no_main] -use std::ffi; use std::fs::File; -use std::io; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::sync::Arc; +use std::{ffi, io}; use libc::{MAP_NORESERVE, MAP_PRIVATE, PROT_READ, PROT_WRITE}; use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{Pmem, UserspaceMapping, VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; +use vm_memory::bitmap::AtomicBitmap; use vm_memory::guest_memory::FileOffset; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic, MmapRegion}; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic, MmapRegion}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/rng.rs b/fuzz/fuzz_targets/rng.rs index b38a96cd4..5666c0a5b 100644 --- a/fuzz/fuzz_targets/rng.rs +++ b/fuzz/fuzz_targets/rng.rs @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/fuzz/fuzz_targets/watchdog.rs b/fuzz/fuzz_targets/watchdog.rs index 2896e9bd3..0dec9ede7 100644 --- a/fuzz/fuzz_targets/watchdog.rs +++ b/fuzz/fuzz_targets/watchdog.rs @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target; use seccompiler::SeccompAction; use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType}; use virtio_queue::{Queue, QueueT}; -use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic}; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index 14b562ad6..c4655b5f2 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -17,9 +17,7 @@ use crate::aarch64::{RegList, VcpuInit}; use crate::arch::x86::{CpuIdEntry, FpuState, LapicState, MsrEntry, SpecialRegisters}; #[cfg(feature = "tdx")] use crate::kvm::{TdxExitDetails, TdxExitStatus}; -use crate::CpuState; -use crate::MpState; -use crate::StandardRegisters; +use crate::{CpuState, MpState, StandardRegisters}; #[cfg(target_arch = "x86_64")] #[derive(Copy, Clone, Default)] diff --git a/hypervisor/src/kvm/aarch64/gic/redist_regs.rs b/hypervisor/src/kvm/aarch64/gic/redist_regs.rs index 2cc3283cd..c1803a12f 100644 --- a/hypervisor/src/kvm/aarch64/gic/redist_regs.rs +++ b/hypervisor/src/kvm/aarch64/gic/redist_regs.rs @@ -11,8 +11,7 @@ use crate::kvm::kvm_bindings::{ KVM_REG_ARM64_SYSREG_OP0_MASK, KVM_REG_ARM64_SYSREG_OP0_SHIFT, KVM_REG_ARM64_SYSREG_OP2_MASK, KVM_REG_ARM64_SYSREG_OP2_SHIFT, KVM_REG_SIZE_U64, }; -use crate::kvm::Register; -use crate::kvm::VcpuKvmState; +use crate::kvm::{Register, VcpuKvmState}; use crate::CpuState; // Relevant redistributor registers that we want to save/restore. diff --git a/hypervisor/src/kvm/aarch64/mod.rs b/hypervisor/src/kvm/aarch64/mod.rs index 1b7f44952..4d074df6a 100644 --- a/hypervisor/src/kvm/aarch64/mod.rs +++ b/hypervisor/src/kvm/aarch64/mod.rs @@ -15,8 +15,8 @@ use kvm_bindings::{ KVM_REG_SIZE_MASK, KVM_REG_SIZE_U32, KVM_REG_SIZE_U64, }; pub use kvm_bindings::{kvm_one_reg as Register, kvm_vcpu_init as VcpuInit, RegList}; +pub use kvm_ioctls::{Cap, Kvm}; use serde::{Deserialize, Serialize}; -pub use {kvm_ioctls::Cap, kvm_ioctls::Kvm}; use crate::kvm::{KvmError, KvmResult}; diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index beda69fc7..f8ad02415 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -19,8 +19,7 @@ use std::os::unix::io::RawFd; use std::result; #[cfg(target_arch = "x86_64")] use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Mutex; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, Mutex, RwLock}; use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd}; use vmm_sys_util::eventfd::EventFd; @@ -34,13 +33,10 @@ pub use crate::aarch64::{ }; #[cfg(target_arch = "aarch64")] use crate::arch::aarch64::gic::{Vgic, VgicConfig}; -use crate::cpu; -use crate::hypervisor; -use crate::vec_with_array_field; use crate::vm::{self, InterruptSourceConfig, VmOps}; -use crate::HypervisorType; #[cfg(target_arch = "aarch64")] use crate::{arm64_core_reg_id, offset_of}; +use crate::{cpu, hypervisor, vec_with_array_field, HypervisorType}; // x86_64 dependencies #[cfg(target_arch = "x86_64")] pub mod x86_64; @@ -62,9 +58,8 @@ use crate::arch::x86::{ }; #[cfg(target_arch = "x86_64")] use crate::ClockData; -use crate::StandardRegisters; use crate::{ - CpuState, IoEventAddress, IrqRoutingEntry, MpState, UserMemoryRegion, + CpuState, IoEventAddress, IrqRoutingEntry, MpState, StandardRegisters, UserMemoryRegion, USER_MEMORY_REGION_LOG_DIRTY, USER_MEMORY_REGION_READ, USER_MEMORY_REGION_WRITE, }; // aarch64 dependencies @@ -73,7 +68,6 @@ pub mod aarch64; #[cfg(target_arch = "aarch64")] use std::mem; -pub use kvm_bindings; pub use kvm_bindings::{ kvm_clock_data, kvm_create_device, kvm_device_type_KVM_DEV_TYPE_VFIO, kvm_guest_debug, kvm_irq_routing, kvm_irq_routing_entry, kvm_mp_state, kvm_userspace_memory_region, @@ -89,12 +83,12 @@ use kvm_bindings::{ }; #[cfg(feature = "tdx")] use kvm_bindings::{kvm_run__bindgen_ty_1, KVMIO}; -pub use kvm_ioctls; pub use kvm_ioctls::{Cap, Kvm}; use thiserror::Error; use vfio_ioctls::VfioDeviceFd; #[cfg(feature = "tdx")] use vmm_sys_util::{ioctl::ioctl_with_val, ioctl_ioc_nr, ioctl_iowr_nr}; +pub use {kvm_bindings, kvm_ioctls}; /// /// Export generically-named wrappers of kvm-bindings for Unix-based platforms /// diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 34c33bb79..7584dda14 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -15,12 +15,9 @@ use vm::DataMatch; use crate::arch::emulator::PlatformEmulator; #[cfg(target_arch = "x86_64")] use crate::arch::x86::emulator::Emulator; -use crate::cpu; -use crate::hypervisor; use crate::mshv::emulator::MshvEmulatorContext; -use crate::vec_with_array_field; use crate::vm::{self, InterruptSourceConfig, VmOps}; -use crate::HypervisorType; +use crate::{cpu, hypervisor, vec_with_array_field, HypervisorType}; #[cfg(feature = "sev_snp")] mod snp_constants; // x86_64 dependencies diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index 712627a63..356cf4172 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -29,8 +29,7 @@ use crate::arch::x86::CpuIdEntry; use crate::cpu::Vcpu; #[cfg(target_arch = "x86_64")] use crate::ClockData; -use crate::UserMemoryRegion; -use crate::{IoEventAddress, IrqRoutingEntry}; +use crate::{IoEventAddress, IrqRoutingEntry, UserMemoryRegion}; /// /// I/O events data matches (32 or 64 bits). diff --git a/net_util/src/ctrl_queue.rs b/net_util/src/ctrl_queue.rs index fef1d61f3..46915b732 100644 --- a/net_util/src/ctrl_queue.rs +++ b/net_util/src/ctrl_queue.rs @@ -16,8 +16,7 @@ use virtio_queue::{Queue, QueueT}; use vm_memory::{ByteValued, Bytes, GuestMemoryError}; use vm_virtio::{AccessPlatform, Translatable}; -use crate::GuestMemoryMmap; -use crate::Tap; +use crate::{GuestMemoryMmap, Tap}; #[derive(Debug)] pub enum Error { diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs index 3cdaf6816..947067148 100644 --- a/net_util/src/lib.rs +++ b/net_util/src/lib.rs @@ -26,7 +26,8 @@ use virtio_bindings::virtio_net::{ VIRTIO_NET_F_GUEST_CSUM, VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_F_MAC, VIRTIO_NET_F_MQ, }; -use vm_memory::{bitmap::AtomicBitmap, ByteValued}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::ByteValued; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/net_util/src/mac.rs b/net_util/src/mac.rs index 0ea5786ad..77ee63e11 100644 --- a/net_util/src/mac.rs +++ b/net_util/src/mac.rs @@ -5,9 +5,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the THIRD-PARTY file. -use std::fmt; -use std::io; use std::str::FromStr; +use std::{fmt, io}; use serde::de::{Deserialize, Deserializer, Error}; use serde::ser::{Serialize, Serializer}; diff --git a/net_util/src/tap.rs b/net_util/src/tap.rs index d30e34450..06f89b560 100644 --- a/net_util/src/tap.rs +++ b/net_util/src/tap.rs @@ -424,10 +424,9 @@ impl AsRawFd for Tap { #[cfg(test)] mod tests { use std::net::Ipv4Addr; - use std::str; use std::sync::{mpsc, Mutex}; - use std::thread; use std::time::Duration; + use std::{str, thread}; use once_cell::sync::Lazy; use pnet::packet::ethernet::{EtherTypes, EthernetPacket, MutableEthernetPacket}; diff --git a/pci/src/msix.rs b/pci/src/msix.rs index faf87dcfa..e72347776 100644 --- a/pci/src/msix.rs +++ b/pci/src/msix.rs @@ -3,13 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause // -use std::io; -use std::result; use std::sync::Arc; +use std::{io, result}; use byteorder::{ByteOrder, LittleEndian}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use vm_device::interrupt::{ InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig, }; diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index 41e491ec6..63aff1af6 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -25,8 +25,10 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vmm_sys_util::eventfd::EventFd; use crate::vfio::{UserMemoryRegion, Vfio, VfioCommon, VfioError, VFIO_COMMON_ID}; -use crate::{BarReprogrammingParams, PciBarConfiguration, VfioPciError}; -use crate::{PciBdf, PciDevice, PciDeviceError, PciSubclass}; +use crate::{ + BarReprogrammingParams, PciBarConfiguration, PciBdf, PciDevice, PciDeviceError, PciSubclass, + VfioPciError, +}; pub struct VfioUserPciDevice { id: String, diff --git a/performance-metrics/src/main.rs b/performance-metrics/src/main.rs index cc78ed4f7..e029b10d8 100644 --- a/performance-metrics/src/main.rs +++ b/performance-metrics/src/main.rs @@ -8,13 +8,11 @@ extern crate test_infra; mod performance_tests; -use std::{ - env, fmt, - process::Command, - sync::{mpsc::channel, Arc}, - thread, - time::Duration, -}; +use std::process::Command; +use std::sync::mpsc::channel; +use std::sync::Arc; +use std::time::Duration; +use std::{env, fmt, thread}; use clap::{Arg, ArgAction, Command as ClapCommand}; use performance_tests::*; diff --git a/performance-metrics/src/performance_tests.rs b/performance-metrics/src/performance_tests.rs index 2192a2919..75cfeff30 100644 --- a/performance-metrics/src/performance_tests.rs +++ b/performance-metrics/src/performance_tests.rs @@ -5,13 +5,11 @@ // Performance tests -use std::fs; use std::path::PathBuf; -use std::thread; use std::time::Duration; +use std::{fs, thread}; -use test_infra::Error as InfraError; -use test_infra::*; +use test_infra::{Error as InfraError, *}; use crate::{mean, PerformanceTestControl}; diff --git a/rate_limiter/src/group.rs b/rate_limiter/src/group.rs index 1b1621ae2..ee91e1b72 100644 --- a/rate_limiter/src/group.rs +++ b/rate_limiter/src/group.rs @@ -6,11 +6,9 @@ use core::panic::AssertUnwindSafe; use std::fs::File; -use std::io; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; -use std::result; use std::sync::{Arc, Mutex}; -use std::thread; +use std::{io, result, thread}; use thiserror::Error; use vmm_sys_util::eventfd::EventFd; @@ -300,12 +298,15 @@ impl Drop for RateLimiterGroup { #[cfg(test)] pub(crate) mod tests { - use std::{os::fd::AsRawFd, thread, time::Duration}; + use std::os::fd::AsRawFd; + use std::thread; + use std::time::Duration; use vmm_sys_util::eventfd::EventFd; use super::RateLimiterGroupHandle; - use crate::{group::RateLimiterGroup, TokenBucket, TokenType, REFILL_TIMER_INTERVAL_MS}; + use crate::group::RateLimiterGroup; + use crate::{TokenBucket, TokenType, REFILL_TIMER_INTERVAL_MS}; impl RateLimiterGroupHandle { pub fn bandwidth(&self) -> Option { diff --git a/rate_limiter/src/lib.rs b/rate_limiter/src/lib.rs index 646d1fba0..627c5a59d 100644 --- a/rate_limiter/src/lib.rs +++ b/rate_limiter/src/lib.rs @@ -520,8 +520,7 @@ impl Default for RateLimiter { #[cfg(test)] pub(crate) mod tests { - use std::fmt; - use std::thread; + use std::{fmt, thread}; use super::*; diff --git a/serial_buffer/src/lib.rs b/serial_buffer/src/lib.rs index f01f31aa7..6b9182d4c 100644 --- a/serial_buffer/src/lib.rs +++ b/serial_buffer/src/lib.rs @@ -3,14 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::{ - collections::VecDeque, - io::Write, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }, -}; +use std::collections::VecDeque; +use std::io::Write; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; const MAX_BUFFER_SIZE: usize = 1 << 20; diff --git a/src/bin/ch-remote.rs b/src/bin/ch-remote.rs index acdfff60a..ca36bd1e3 100644 --- a/src/bin/ch-remote.rs +++ b/src/bin/ch-remote.rs @@ -3,16 +3,15 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::fmt; use std::io::Read; use std::marker::PhantomData; use std::os::unix::net::UnixStream; -use std::process; +use std::{fmt, process}; -use api_client::simple_api_command; -use api_client::simple_api_command_with_fds; -use api_client::simple_api_full_command; -use api_client::Error as ApiClientError; +use api_client::{ + simple_api_command, simple_api_command_with_fds, simple_api_full_command, + Error as ApiClientError, +}; use clap::{Arg, ArgAction, ArgMatches, Command}; use option_parser::{ByteSized, ByteSizedParseError}; #[cfg(feature = "dbus_api")] diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index efba7ccaa..605b24736 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -5,22 +5,18 @@ #![allow(clippy::undocumented_unsafe_blocks)] -use std::env; use std::ffi::OsStr; use std::fmt::Display; -use std::io; use std::io::{Read, Write}; -use std::net::TcpListener; -use std::net::TcpStream; +use std::net::{TcpListener, TcpStream}; use std::os::unix::fs::PermissionsExt; use std::os::unix::io::{AsRawFd, FromRawFd}; use std::path::Path; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::str::FromStr; use std::sync::Mutex; -use std::thread; use std::time::Duration; -use std::{fmt, fs}; +use std::{env, fmt, fs, io, thread}; use once_cell::sync::Lazy; use serde_json::Value; diff --git a/tests/integration.rs b/tests/integration.rs index d05523f2b..2e2aa4620 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -11,24 +11,19 @@ extern crate test_infra; use std::collections::HashMap; -use std::fs; -use std::io; -use std::io::BufRead; -use std::io::Read; -use std::io::Seek; -use std::io::Write; +use std::io::{BufRead, Read, Seek, Write}; use std::os::unix::io::AsRawFd; use std::path::PathBuf; use std::process::{Child, Command, Stdio}; use std::string::String; -use std::sync::mpsc; use std::sync::mpsc::Receiver; -use std::sync::Mutex; -use std::thread; +use std::sync::{mpsc, Mutex}; +use std::{fs, io, thread}; use net_util::MacAddr; use test_infra::*; -use vmm_sys_util::{tempdir::TempDir, tempfile::TempFile}; +use vmm_sys_util::tempdir::TempDir; +use vmm_sys_util::tempfile::TempFile; use wait_timeout::ChildExt; // Constant taken from the VMM crate. @@ -2347,7 +2342,8 @@ fn make_guest_panic(guest: &Guest) { } mod common_parallel { - use std::{fs::OpenOptions, io::SeekFrom}; + use std::fs::OpenOptions; + use std::io::SeekFrom; use crate::*; diff --git a/tpm/src/emulator.rs b/tpm/src/emulator.rs index dcd2dc771..3b892d27c 100644 --- a/tpm/src/emulator.rs +++ b/tpm/src/emulator.rs @@ -8,13 +8,14 @@ use std::path::Path; use std::{mem, ptr}; use anyhow::anyhow; -use libc::c_void; -use libc::{sockaddr_storage, socklen_t}; +use libc::{c_void, sockaddr_storage, socklen_t}; use thiserror::Error; use crate::socket::SocketDev; -use crate::{Commands, MemberType, Ptm, PtmCap, PtmEst, PtmInit, PtmResult, PtmSetBufferSize}; -use crate::{TPM_CRB_BUFFER_MAX, TPM_SUCCESS}; +use crate::{ + Commands, MemberType, Ptm, PtmCap, PtmEst, PtmInit, PtmResult, PtmSetBufferSize, + TPM_CRB_BUFFER_MAX, TPM_SUCCESS, +}; const TPM_REQ_HDR_SIZE: usize = 10; diff --git a/vhost_user_block/src/lib.rs b/vhost_user_block/src/lib.rs index 09a21d0fc..5e942a530 100644 --- a/vhost_user_block/src/lib.rs +++ b/vhost_user_block/src/lib.rs @@ -8,41 +8,32 @@ // // SPDX-License-Identifier: (Apache-2.0 AND BSD-3-Clause) -use std::fs::File; -use std::fs::OpenOptions; -use std::io::Read; -use std::io::{Seek, SeekFrom, Write}; -use std::ops::Deref; -use std::ops::DerefMut; +use std::fs::{File, OpenOptions}; +use std::io::{Read, Seek, SeekFrom, Write}; +use std::ops::{Deref, DerefMut}; use std::os::unix::fs::OpenOptionsExt; use std::path::PathBuf; -use std::process; -use std::result; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex, RwLock, RwLockWriteGuard}; use std::time::Instant; -use std::{convert, error, fmt, io}; +use std::{convert, error, fmt, io, process, result}; -use block::{ - build_serial, - qcow::{self, ImageType, QcowFile}, - Request, VirtioBlockConfig, -}; +use block::qcow::{self, ImageType, QcowFile}; +use block::{build_serial, Request, VirtioBlockConfig}; use libc::EFD_NONBLOCK; use log::*; use option_parser::{OptionParser, OptionParserError, Toggle}; use vhost::vhost_user::message::*; use vhost::vhost_user::Listener; -use vhost_user_backend::{ - bitmap::BitmapMmapRegion, VhostUserBackendMut, VhostUserDaemon, VringRwLock, VringState, VringT, -}; +use vhost_user_backend::bitmap::BitmapMmapRegion; +use vhost_user_backend::{VhostUserBackendMut, VhostUserDaemon, VringRwLock, VringState, VringT}; use virtio_bindings::virtio_blk::*; use virtio_bindings::virtio_config::VIRTIO_F_VERSION_1; use virtio_bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX; use virtio_queue::QueueT; -use vm_memory::GuestAddressSpace; -use vm_memory::{ByteValued, Bytes, GuestMemoryAtomic}; -use vmm_sys_util::{epoll::EventSet, eventfd::EventFd}; +use vm_memory::{ByteValued, Bytes, GuestAddressSpace, GuestMemoryAtomic}; +use vmm_sys_util::epoll::EventSet; +use vmm_sys_util::eventfd::EventFd; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/vhost_user_net/src/lib.rs b/vhost_user_net/src/lib.rs index 85b420cd1..97449aaa7 100644 --- a/vhost_user_net/src/lib.rs +++ b/vhost_user_net/src/lib.rs @@ -6,30 +6,27 @@ // // SPDX-License-Identifier: (Apache-2.0 AND BSD-3-Clause) -use std::fmt; -use std::io; use std::net::Ipv4Addr; use std::ops::Deref; use std::os::unix::io::{AsRawFd, RawFd}; -use std::process; use std::sync::{Arc, Mutex, RwLock}; +use std::{fmt, io, process}; use libc::EFD_NONBLOCK; use log::*; use net_util::{ open_tap, MacAddr, NetCounters, NetQueuePair, OpenTapError, RxVirtio, Tap, TxVirtio, }; -use option_parser::Toggle; -use option_parser::{OptionParser, OptionParserError}; +use option_parser::{OptionParser, OptionParserError, Toggle}; use vhost::vhost_user::message::*; use vhost::vhost_user::Listener; use vhost_user_backend::bitmap::BitmapMmapRegion; use vhost_user_backend::{VhostUserBackendMut, VhostUserDaemon, VringRwLock, VringT}; use virtio_bindings::virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1}; use virtio_bindings::virtio_net::*; -use vm_memory::GuestAddressSpace; -use vm_memory::GuestMemoryAtomic; -use vmm_sys_util::{epoll::EventSet, eventfd::EventFd}; +use vm_memory::{GuestAddressSpace, GuestMemoryAtomic}; +use vmm_sys_util::epoll::EventSet; +use vmm_sys_util::eventfd::EventFd; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/virtio-devices/src/balloon.rs b/virtio-devices/src/balloon.rs index 1fd9b7b8c..d9fa144cd 100644 --- a/virtio-devices/src/balloon.rs +++ b/virtio-devices/src/balloon.rs @@ -18,7 +18,8 @@ use std::io::{self, Write}; use std::mem::size_of; use std::os::unix::io::AsRawFd; use std::result; -use std::sync::{atomic::AtomicBool, Arc, Barrier}; +use std::sync::atomic::AtomicBool; +use std::sync::{Arc, Barrier}; use anyhow::anyhow; use seccompiler::SeccompAction; @@ -33,11 +34,12 @@ use vm_memory::{ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; +use crate::seccomp_filters::Thread; +use crate::thread_helper::spawn_virtio_thread; use crate::{ - seccomp_filters::Thread, thread_helper::spawn_virtio_thread, ActivateResult, EpollHelper, - EpollHelperError, EpollHelperHandler, GuestMemoryMmap, VirtioCommon, VirtioDevice, - VirtioDeviceType, VirtioInterrupt, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, - VIRTIO_F_VERSION_1, + ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, GuestMemoryMmap, + VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterrupt, VirtioInterruptType, + EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1, }; const QUEUE_SIZE: u16 = 128; diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index f06b17bbc..e0c758e8a 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -8,23 +8,18 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::VecDeque; -use std::io; +use std::collections::{BTreeMap, HashMap, VecDeque}; use std::num::Wrapping; use std::ops::Deref; use std::os::unix::io::AsRawFd; use std::path::PathBuf; -use std::result; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Barrier}; +use std::{io, result}; use anyhow::anyhow; -use block::{ - async_io::AsyncIo, async_io::AsyncIoError, async_io::DiskFile, build_serial, Request, - RequestType, VirtioBlockConfig, -}; +use block::async_io::{AsyncIo, AsyncIoError, DiskFile}; +use block::{build_serial, Request, RequestType, VirtioBlockConfig}; use rate_limiter::group::{RateLimiterGroup, RateLimiterGroupHandle}; use rate_limiter::TokenType; use seccompiler::SeccompAction; @@ -39,15 +34,14 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ - ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, VirtioCommon, - VirtioDevice, VirtioDeviceType, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, + ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, + Error as DeviceError, VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, + EPOLL_HELPER_EVENT_LAST, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::GuestMemoryMmap; -use crate::VirtioInterrupt; +use crate::{GuestMemoryMmap, VirtioInterrupt}; const SECTOR_SHIFT: u8 = 9; pub const SECTOR_SIZE: u64 = 0x01 << SECTOR_SHIFT; diff --git a/virtio-devices/src/console.rs b/virtio-devices/src/console.rs index 9fce951ee..b6bdeb078 100644 --- a/virtio-devices/src/console.rs +++ b/virtio-devices/src/console.rs @@ -1,15 +1,13 @@ // Copyright 2019 Intel Corporation. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -use std::cmp; use std::collections::VecDeque; use std::fs::File; -use std::io; use std::io::{Read, Write}; use std::os::unix::io::AsRawFd; -use std::result; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Barrier, Mutex}; +use std::{cmp, io, result}; use anyhow::anyhow; use libc::{EFD_NONBLOCK, TIOCGWINSZ}; @@ -23,16 +21,14 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ - ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, VirtioCommon, VirtioDevice, - VirtioDeviceType, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_IOMMU_PLATFORM, - VIRTIO_F_VERSION_1, + ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, Error as DeviceError, + VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, + VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::GuestMemoryMmap; -use crate::VirtioInterrupt; +use crate::{GuestMemoryMmap, VirtioInterrupt}; const QUEUE_SIZE: u16 = 256; const NUM_QUEUES: usize = 2; diff --git a/virtio-devices/src/device.rs b/virtio-devices/src/device.rs index e2ac65319..77501187a 100644 --- a/virtio-devices/src/device.rs +++ b/virtio-devices/src/device.rs @@ -9,18 +9,15 @@ use std::collections::HashMap; use std::io::Write; use std::num::Wrapping; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, Barrier, -}; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Barrier}; use std::thread; use libc::EFD_NONBLOCK; use virtio_queue::Queue; use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestUsize}; use vm_migration::{MigratableError, Pausable}; -use vm_virtio::AccessPlatform; -use vm_virtio::VirtioDeviceType; +use vm_virtio::{AccessPlatform, VirtioDeviceType}; use vmm_sys_util::eventfd::EventFd; use crate::{ diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index ba304f2c5..b572061ec 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -3,13 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause use std::collections::BTreeMap; -use std::io; use std::mem::size_of; use std::ops::Bound::Included; use std::os::unix::io::AsRawFd; -use std::result; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier, Mutex, RwLock}; +use std::{io, result}; use anyhow::anyhow; use seccompiler::SeccompAction; @@ -25,15 +24,13 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ - ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, VirtioCommon, VirtioDevice, - VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1, + ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, Error as DeviceError, + VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::GuestMemoryMmap; -use crate::{DmaRemapping, VirtioInterrupt, VirtioInterruptType}; +use crate::{DmaRemapping, GuestMemoryMmap, VirtioInterrupt, VirtioInterruptType}; /// Queues sizes const QUEUE_SIZE: u16 = 256; diff --git a/virtio-devices/src/lib.rs b/virtio-devices/src/lib.rs index 28445c3d4..4a4f15e7b 100644 --- a/virtio-devices/src/lib.rs +++ b/virtio-devices/src/lib.rs @@ -39,7 +39,8 @@ pub mod vhost_user; pub mod vsock; pub mod watchdog; -use vm_memory::{bitmap::AtomicBitmap, GuestAddress, GuestMemory}; +use vm_memory::bitmap::AtomicBitmap; +use vm_memory::{GuestAddress, GuestMemory}; use vm_virtio::VirtioDeviceType; pub use self::balloon::Balloon; diff --git a/virtio-devices/src/mem.rs b/virtio-devices/src/mem.rs index d4b01f4a1..034015a85 100644 --- a/virtio-devices/src/mem.rs +++ b/virtio-devices/src/mem.rs @@ -15,13 +15,11 @@ // limitations under the License. use std::collections::BTreeMap; -use std::io; use std::mem::size_of; use std::os::unix::io::{AsRawFd, RawFd}; -use std::result; use std::sync::atomic::AtomicBool; -use std::sync::mpsc; -use std::sync::{Arc, Barrier, Mutex}; +use std::sync::{mpsc, Arc, Barrier, Mutex}; +use std::{io, result}; use anyhow::anyhow; use seccompiler::SeccompAction; @@ -37,15 +35,14 @@ use vm_migration::protocol::MemoryRangeTable; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ - ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, VirtioCommon, - VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1, + ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, + Error as DeviceError, VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, + VIRTIO_F_VERSION_1, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::{GuestMemoryMmap, GuestRegionMmap}; -use crate::{VirtioInterrupt, VirtioInterruptType}; +use crate::{GuestMemoryMmap, GuestRegionMmap, VirtioInterrupt, VirtioInterruptType}; const QUEUE_SIZE: u16 = 128; const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE]; diff --git a/virtio-devices/src/net.rs b/virtio-devices/src/net.rs index 2d312d27c..38a14af08 100644 --- a/virtio-devices/src/net.rs +++ b/virtio-devices/src/net.rs @@ -10,18 +10,16 @@ use std::net::Ipv4Addr; use std::num::Wrapping; use std::ops::Deref; use std::os::unix::io::{AsRawFd, RawFd}; -use std::result; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier}; -use std::thread; +use std::{result, thread}; use anyhow::anyhow; #[cfg(not(fuzzing))] use net_util::virtio_features_to_tap_offload; -use net_util::CtrlQueue; use net_util::{ - build_net_config_space, build_net_config_space_with_mq, open_tap, MacAddr, NetCounters, - NetQueuePair, OpenTapError, RxVirtio, Tap, TapError, TxVirtio, VirtioNetConfig, + build_net_config_space, build_net_config_space_with_mq, open_tap, CtrlQueue, MacAddr, + NetCounters, NetQueuePair, OpenTapError, RxVirtio, Tap, TapError, TxVirtio, VirtioNetConfig, }; use seccompiler::SeccompAction; use serde::{Deserialize, Serialize}; @@ -35,16 +33,14 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, - RateLimiterConfig, VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, - EPOLL_HELPER_EVENT_LAST, + Error as DeviceError, RateLimiterConfig, VirtioCommon, VirtioDevice, VirtioDeviceType, + VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::GuestMemoryMmap; -use crate::VirtioInterrupt; +use crate::{GuestMemoryMmap, VirtioInterrupt}; /// Control queue // Event available on the control queue. diff --git a/virtio-devices/src/pmem.rs b/virtio-devices/src/pmem.rs index b0507445c..d46cdd6f2 100644 --- a/virtio-devices/src/pmem.rs +++ b/virtio-devices/src/pmem.rs @@ -7,12 +7,11 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause use std::fs::File; -use std::io; use std::mem::size_of; use std::os::unix::io::AsRawFd; -use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier}; +use std::{io, result}; use anyhow::anyhow; use seccompiler::SeccompAction; @@ -27,16 +26,14 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, - UserspaceMapping, VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, - VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, + Error as DeviceError, UserspaceMapping, VirtioCommon, VirtioDevice, VirtioDeviceType, + EPOLL_HELPER_EVENT_LAST, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::{GuestMemoryMmap, MmapRegion}; -use crate::{VirtioInterrupt, VirtioInterruptType}; +use crate::{GuestMemoryMmap, MmapRegion, VirtioInterrupt, VirtioInterruptType}; const QUEUE_SIZE: u16 = 256; const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE]; diff --git a/virtio-devices/src/rng.rs b/virtio-devices/src/rng.rs index 5fde51e88..918285ac7 100644 --- a/virtio-devices/src/rng.rs +++ b/virtio-devices/src/rng.rs @@ -5,11 +5,10 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause use std::fs::File; -use std::io; use std::os::unix::io::AsRawFd; -use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier}; +use std::{io, result}; use anyhow::anyhow; use seccompiler::SeccompAction; @@ -21,16 +20,14 @@ use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottabl use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ - ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, VirtioCommon, - VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_IOMMU_PLATFORM, - VIRTIO_F_VERSION_1, + ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, + Error as DeviceError, VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, + VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::GuestMemoryMmap; -use crate::{VirtioInterrupt, VirtioInterruptType}; +use crate::{GuestMemoryMmap, VirtioInterrupt, VirtioInterruptType}; const QUEUE_SIZE: u16 = 256; const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE]; diff --git a/virtio-devices/src/seccomp_filters.rs b/virtio-devices/src/seccomp_filters.rs index f5a5fac60..2579e4f14 100644 --- a/virtio-devices/src/seccomp_filters.rs +++ b/virtio-devices/src/seccomp_filters.rs @@ -4,9 +4,10 @@ // // SPDX-License-Identifier: Apache-2.0 +use seccompiler::SeccompCmpOp::Eq; use seccompiler::{ - BpfProgram, Error, SeccompAction, SeccompCmpArgLen as ArgLen, SeccompCmpOp::Eq, - SeccompCondition as Cond, SeccompFilter, SeccompRule, + BpfProgram, Error, SeccompAction, SeccompCmpArgLen as ArgLen, SeccompCondition as Cond, + SeccompFilter, SeccompRule, }; pub enum Thread { diff --git a/virtio-devices/src/thread_helper.rs b/virtio-devices/src/thread_helper.rs index 114fb1012..41eb99b7c 100644 --- a/virtio-devices/src/thread_helper.rs +++ b/virtio-devices/src/thread_helper.rs @@ -3,19 +3,15 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::{ - panic::AssertUnwindSafe, - thread::{self, JoinHandle}, -}; +use std::panic::AssertUnwindSafe; +use std::thread::{self, JoinHandle}; use seccompiler::{apply_filter, SeccompAction}; use vmm_sys_util::eventfd::EventFd; -use crate::{ - epoll_helper::EpollHelperError, - seccomp_filters::{get_seccomp_filter, Thread}, - ActivateError, -}; +use crate::epoll_helper::EpollHelperError; +use crate::seccomp_filters::{get_seccomp_filter, Thread}; +use crate::ActivateError; pub(crate) fn spawn_virtio_thread( name: &str, diff --git a/virtio-devices/src/transport/pci_common_config.rs b/virtio-devices/src/transport/pci_common_config.rs index 79fbb7e13..c87e36e92 100644 --- a/virtio-devices/src/transport/pci_common_config.rs +++ b/virtio-devices/src/transport/pci_common_config.rs @@ -410,8 +410,7 @@ mod tests { use vmm_sys_util::eventfd::EventFd; use super::*; - use crate::GuestMemoryMmap; - use crate::{ActivateResult, VirtioInterrupt}; + use crate::{ActivateResult, GuestMemoryMmap, VirtioInterrupt}; struct DummyDevice(u32); const QUEUE_SIZE: u16 = 256; diff --git a/virtio-devices/src/transport/pci_device.rs b/virtio-devices/src/transport/pci_device.rs index 0551ffc98..6af4afc92 100644 --- a/virtio-devices/src/transport/pci_device.rs +++ b/virtio-devices/src/transport/pci_device.rs @@ -36,11 +36,10 @@ use vmm_sys_util::eventfd::EventFd; use super::pci_common_config::VirtioPciCommonConfigState; use crate::transport::{VirtioPciCommonConfig, VirtioTransport, VIRTIO_PCI_COMMON_CONFIG_ID}; -use crate::GuestMemoryMmap; use crate::{ - ActivateResult, VirtioDevice, VirtioDeviceType, VirtioInterrupt, VirtioInterruptType, - DEVICE_ACKNOWLEDGE, DEVICE_DRIVER, DEVICE_DRIVER_OK, DEVICE_FAILED, DEVICE_FEATURES_OK, - DEVICE_INIT, + ActivateResult, GuestMemoryMmap, VirtioDevice, VirtioDeviceType, VirtioInterrupt, + VirtioInterruptType, DEVICE_ACKNOWLEDGE, DEVICE_DRIVER, DEVICE_DRIVER_OK, DEVICE_FAILED, + DEVICE_FEATURES_OK, DEVICE_INIT, }; /// Vector value used to disable MSI for a queue. diff --git a/virtio-devices/src/vdpa.rs b/virtio-devices/src/vdpa.rs index f61af9e79..4f3ac1e15 100644 --- a/virtio-devices/src/vdpa.rs +++ b/virtio-devices/src/vdpa.rs @@ -3,24 +3,19 @@ // SPDX-License-Identifier: Apache-2.0 // -use std::{ - collections::BTreeMap, - io, result, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, Mutex, - }, -}; +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex}; +use std::{io, result}; use anyhow::anyhow; use serde::{Deserialize, Serialize}; use thiserror::Error; -use vhost::{ - vdpa::{VhostVdpa, VhostVdpaIovaRange}, - vhost_kern::VhostKernFeatures, - vhost_kern::{vdpa::VhostKernVdpa, vhost_binding::VHOST_BACKEND_F_SUSPEND}, - VhostBackend, VringConfigData, -}; +use vhost::vdpa::{VhostVdpa, VhostVdpaIovaRange}; +use vhost::vhost_kern::vdpa::VhostKernVdpa; +use vhost::vhost_kern::vhost_binding::VHOST_BACKEND_F_SUSPEND; +use vhost::vhost_kern::VhostKernFeatures; +use vhost::{VhostBackend, VringConfigData}; use virtio_queue::{Descriptor, Queue, QueueT}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; diff --git a/virtio-devices/src/vhost_user/blk.rs b/virtio-devices/src/vhost_user/blk.rs index d37f9e7ea..531293618 100644 --- a/virtio-devices/src/vhost_user/blk.rs +++ b/virtio-devices/src/vhost_user/blk.rs @@ -1,11 +1,9 @@ // Copyright 2019 Intel Corporation. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -use std::mem; -use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, Mutex}; -use std::thread; +use std::{mem, result, thread}; use block::VirtioBlockConfig; use seccompiler::SeccompAction; @@ -22,10 +20,8 @@ use virtio_bindings::virtio_blk::{ }; use virtio_queue::Queue; use vm_memory::{ByteValued, GuestMemoryAtomic}; -use vm_migration::{ - protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, - Transportable, -}; +use vm_migration::protocol::MemoryRangeTable; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; use super::super::{ActivateResult, VirtioCommon, VirtioDevice, VirtioDeviceType}; @@ -34,8 +30,7 @@ use super::{Error, Result, DEFAULT_VIRTIO_FEATURES}; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; use crate::vhost_user::VhostUserCommon; -use crate::{GuestMemoryMmap, GuestRegionMmap}; -use crate::{VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM}; +use crate::{GuestMemoryMmap, GuestRegionMmap, VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM}; const DEFAULT_QUEUE_NUMBER: usize = 1; diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 0513d4e1b..1a24f1c2d 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -1,10 +1,9 @@ // Copyright 2019 Intel Corporation. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, Mutex}; -use std::thread; +use std::{result, thread}; use seccompiler::SeccompAction; use serde::{Deserialize, Serialize}; @@ -13,10 +12,8 @@ use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatu use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontend, VhostUserFrontendReqHandler}; use virtio_queue::Queue; use vm_memory::{ByteValued, GuestMemoryAtomic}; -use vm_migration::{ - protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, - Transportable, -}; +use vm_migration::protocol::MemoryRangeTable; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; use super::vu_common_ctrl::VhostUserHandle; @@ -25,10 +22,10 @@ use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; use crate::vhost_user::VhostUserCommon; use crate::{ - ActivateResult, UserspaceMapping, VirtioCommon, VirtioDevice, VirtioDeviceType, - VirtioInterrupt, VirtioSharedMemoryList, VIRTIO_F_IOMMU_PLATFORM, + ActivateResult, GuestMemoryMmap, GuestRegionMmap, MmapRegion, UserspaceMapping, VirtioCommon, + VirtioDevice, VirtioDeviceType, VirtioInterrupt, VirtioSharedMemoryList, + VIRTIO_F_IOMMU_PLATFORM, }; -use crate::{GuestMemoryMmap, GuestRegionMmap, MmapRegion}; const NUM_QUEUE_OFFSET: usize = 1; const DEFAULT_QUEUE_NUMBER: usize = 2; diff --git a/virtio-devices/src/vhost_user/mod.rs b/virtio-devices/src/vhost_user/mod.rs index bb84d157f..56d641528 100644 --- a/virtio-devices/src/vhost_user/mod.rs +++ b/virtio-devices/src/vhost_user/mod.rs @@ -4,7 +4,8 @@ use std::io; use std::ops::Deref; use std::os::unix::io::AsRawFd; -use std::sync::{atomic::AtomicBool, Arc, Barrier, Mutex}; +use std::sync::atomic::AtomicBool; +use std::sync::{Arc, Barrier, Mutex}; use anyhow::anyhow; use serde::{Deserialize, Serialize}; @@ -14,13 +15,11 @@ use vhost::vhost_user::message::{ }; use vhost::vhost_user::{FrontendReqHandler, VhostUserFrontendReqHandler}; use vhost::Error as VhostError; -use virtio_queue::Error as QueueError; -use virtio_queue::Queue; -use vm_memory::{ - mmap::MmapRegionError, Address, Error as MmapError, GuestAddressSpace, GuestMemory, - GuestMemoryAtomic, -}; -use vm_migration::{protocol::MemoryRangeTable, MigratableError, Snapshot}; +use virtio_queue::{Error as QueueError, Queue}; +use vm_memory::mmap::MmapRegionError; +use vm_memory::{Address, Error as MmapError, GuestAddressSpace, GuestMemory, GuestMemoryAtomic}; +use vm_migration::protocol::MemoryRangeTable; +use vm_migration::{MigratableError, Snapshot}; use vmm_sys_util::eventfd::EventFd; use vu_common_ctrl::VhostUserHandle; diff --git a/virtio-devices/src/vhost_user/net.rs b/virtio-devices/src/vhost_user/net.rs index 596172fa8..54304e535 100644 --- a/virtio-devices/src/vhost_user/net.rs +++ b/virtio-devices/src/vhost_user/net.rs @@ -1,10 +1,9 @@ // Copyright 2019 Intel Corporation. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, Mutex}; -use std::thread; +use std::{result, thread}; use net_util::{build_net_config_space, CtrlQueue, MacAddr, VirtioNetConfig}; use seccompiler::SeccompAction; @@ -20,10 +19,8 @@ use virtio_bindings::virtio_net::{ use virtio_bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX; use virtio_queue::{Queue, QueueT}; use vm_memory::{ByteValued, GuestMemoryAtomic}; -use vm_migration::{ - protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, - Transportable, -}; +use vm_migration::protocol::MemoryRangeTable; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; use crate::seccomp_filters::Thread; @@ -31,10 +28,10 @@ use crate::thread_helper::spawn_virtio_thread; use crate::vhost_user::vu_common_ctrl::{VhostUserConfig, VhostUserHandle}; use crate::vhost_user::{Error, Result, VhostUserCommon}; use crate::{ - ActivateResult, NetCtrlEpollHandler, VirtioCommon, VirtioDevice, VirtioDeviceType, - VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_RING_EVENT_IDX, VIRTIO_F_VERSION_1, + ActivateResult, GuestMemoryMmap, GuestRegionMmap, NetCtrlEpollHandler, VirtioCommon, + VirtioDevice, VirtioDeviceType, VirtioInterrupt, VIRTIO_F_IOMMU_PLATFORM, + VIRTIO_F_RING_EVENT_IDX, VIRTIO_F_VERSION_1, }; -use crate::{GuestMemoryMmap, GuestRegionMmap}; const DEFAULT_QUEUE_NUMBER: usize = 2; diff --git a/virtio-devices/src/vsock/csm/connection.rs b/virtio-devices/src/vsock/csm/connection.rs index c0372ae44..59c161da8 100644 --- a/virtio-devices/src/vsock/csm/connection.rs +++ b/virtio-devices/src/vsock/csm/connection.rs @@ -88,9 +88,8 @@ use std::time::{Duration, Instant}; use super::super::defs::uapi; use super::super::packet::VsockPacket; use super::super::{Result as VsockResult, VsockChannel, VsockEpollListener, VsockError}; -use super::defs; use super::txbuf::TxBuf; -use super::{ConnState, Error, PendingRx, PendingRxSet, Result}; +use super::{defs, ConnState, Error, PendingRx, PendingRxSet, Result}; /// A self-managing connection object, that handles communication between a guest-side AF_VSOCK /// socket and a host-side `Read + Write + AsRawFd` stream. diff --git a/virtio-devices/src/vsock/csm/txbuf.rs b/virtio-devices/src/vsock/csm/txbuf.rs index 03d668727..4c16913f3 100644 --- a/virtio-devices/src/vsock/csm/txbuf.rs +++ b/virtio-devices/src/vsock/csm/txbuf.rs @@ -5,8 +5,7 @@ use std::io::Write; use std::num::Wrapping; -use super::defs; -use super::{Error, Result}; +use super::{defs, Error, Result}; /// A simple ring-buffer implementation, used by vsock connections to buffer TX (guest -> host) /// data. Memory for this buffer is allocated lazily, since buffering will only be needed when @@ -144,9 +143,7 @@ impl TxBuf { #[cfg(test)] mod tests { - use std::io::Error as IoError; - use std::io::ErrorKind; - use std::io::Result as IoResult; + use std::io::{Error as IoError, ErrorKind, Result as IoResult}; use super::*; diff --git a/virtio-devices/src/vsock/device.rs b/virtio-devices/src/vsock/device.rs index 3eafd6d55..7f857bfdc 100644 --- a/virtio-devices/src/vsock/device.rs +++ b/virtio-devices/src/vsock/device.rs @@ -8,22 +8,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the THIRD-PARTY file. -use std::io; use std::os::unix::io::AsRawFd; use std::path::PathBuf; -use std::result; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Barrier, RwLock}; +use std::{io, result}; use anyhow::anyhow; use byteorder::{ByteOrder, LittleEndian}; use seccompiler::SeccompAction; use serde::{Deserialize, Serialize}; -use virtio_queue::Queue; -use virtio_queue::QueueOwnedT; -use virtio_queue::QueueT; -use vm_memory::GuestAddressSpace; -use vm_memory::GuestMemoryAtomic; +use virtio_queue::{Queue, QueueOwnedT, QueueT}; +use vm_memory::{GuestAddressSpace, GuestMemoryAtomic}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vm_virtio::AccessPlatform; use vmm_sys_util::eventfd::EventFd; @@ -49,13 +45,12 @@ use vmm_sys_util::eventfd::EventFd; /// use super::{VsockBackend, VsockPacket}; use crate::seccomp_filters::Thread; -use crate::Error as DeviceError; -use crate::GuestMemoryMmap; -use crate::VirtioInterrupt; +use crate::thread_helper::spawn_virtio_thread; use crate::{ - thread_helper::spawn_virtio_thread, ActivateResult, EpollHelper, EpollHelperError, - EpollHelperHandler, VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType, - EPOLL_HELPER_EVENT_LAST, VIRTIO_F_IN_ORDER, VIRTIO_F_IOMMU_PLATFORM, VIRTIO_F_VERSION_1, + ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, Error as DeviceError, + GuestMemoryMmap, VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterrupt, + VirtioInterruptType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_IN_ORDER, VIRTIO_F_IOMMU_PLATFORM, + VIRTIO_F_VERSION_1, }; const QUEUE_SIZE: u16 = 256; diff --git a/virtio-devices/src/vsock/mod.rs b/virtio-devices/src/vsock/mod.rs index 257032955..8db365b31 100644 --- a/virtio-devices/src/vsock/mod.rs +++ b/virtio-devices/src/vsock/mod.rs @@ -18,8 +18,7 @@ use std::os::unix::io::RawFd; use packet::VsockPacket; pub use self::device::Vsock; -pub use self::unix::VsockUnixBackend; -pub use self::unix::VsockUnixError; +pub use self::unix::{VsockUnixBackend, VsockUnixError}; mod defs { @@ -178,8 +177,7 @@ mod tests { use super::*; use crate::device::{VirtioInterrupt, VirtioInterruptType}; use crate::epoll_helper::EpollHelperHandler; - use crate::EpollHelper; - use crate::GuestMemoryMmap; + use crate::{EpollHelper, GuestMemoryMmap}; pub struct NoopVirtioInterrupt {} diff --git a/virtio-devices/src/vsock/packet.rs b/virtio-devices/src/vsock/packet.rs index 094dd20e9..01ee18fbb 100644 --- a/virtio-devices/src/vsock/packet.rs +++ b/virtio-devices/src/vsock/packet.rs @@ -24,8 +24,7 @@ use virtio_queue::DescriptorChain; use vm_memory::{Address, GuestMemory}; use vm_virtio::{AccessPlatform, Translatable}; -use super::defs; -use super::{Result, VsockError}; +use super::{defs, Result, VsockError}; use crate::get_host_address_range; // The vsock packet header is defined by the C struct: diff --git a/virtio-devices/src/vsock/unix/muxer.rs b/virtio-devices/src/vsock/unix/muxer.rs index 5ff31301c..55e819d4b 100644 --- a/virtio-devices/src/vsock/unix/muxer.rs +++ b/virtio-devices/src/vsock/unix/muxer.rs @@ -50,11 +50,9 @@ use super::super::packet::VsockPacket; use super::super::{ Result as VsockResult, VsockBackend, VsockChannel, VsockEpollListener, VsockError, }; -use super::defs; use super::muxer_killq::MuxerKillQ; use super::muxer_rxq::MuxerRxQ; -use super::MuxerConnection; -use super::{Error, Result}; +use super::{defs, Error, MuxerConnection, Result}; /// A unique identifier of a `MuxerConnection` object. Connections are stored in a hash map, /// keyed by a `ConnMapKey` object. diff --git a/virtio-devices/src/vsock/unix/muxer_killq.rs b/virtio-devices/src/vsock/unix/muxer_killq.rs index 10b2c391c..925f4d938 100644 --- a/virtio-devices/src/vsock/unix/muxer_killq.rs +++ b/virtio-devices/src/vsock/unix/muxer_killq.rs @@ -28,9 +28,8 @@ use std::collections::{HashMap, VecDeque}; use std::time::Instant; -use super::defs; use super::muxer::ConnMapKey; -use super::MuxerConnection; +use super::{defs, MuxerConnection}; /// A kill queue item, holding the connection key and the scheduled time for termination. /// diff --git a/virtio-devices/src/vsock/unix/muxer_rxq.rs b/virtio-devices/src/vsock/unix/muxer_rxq.rs index 5cdbb0e72..701db3459 100644 --- a/virtio-devices/src/vsock/unix/muxer_rxq.rs +++ b/virtio-devices/src/vsock/unix/muxer_rxq.rs @@ -19,9 +19,8 @@ use std::collections::{HashMap, VecDeque}; use super::super::VsockChannel; -use super::defs; use super::muxer::{ConnMapKey, MuxerRx}; -use super::MuxerConnection; +use super::{defs, MuxerConnection}; /// The muxer RX queue. /// diff --git a/virtio-devices/src/watchdog.rs b/virtio-devices/src/watchdog.rs index a45b640c8..4efd6318e 100644 --- a/virtio-devices/src/watchdog.rs +++ b/virtio-devices/src/watchdog.rs @@ -22,15 +22,14 @@ use vm_memory::{Bytes, GuestAddressSpace, GuestMemoryAtomic}; use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; -use super::Error as DeviceError; use super::{ - ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, VirtioCommon, - VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, VIRTIO_F_VERSION_1, + ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler, + Error as DeviceError, VirtioCommon, VirtioDevice, VirtioDeviceType, EPOLL_HELPER_EVENT_LAST, + VIRTIO_F_VERSION_1, }; use crate::seccomp_filters::Thread; use crate::thread_helper::spawn_virtio_thread; -use crate::GuestMemoryMmap; -use crate::{VirtioInterrupt, VirtioInterruptType}; +use crate::{GuestMemoryMmap, VirtioInterrupt, VirtioInterruptType}; const QUEUE_SIZE: u16 = 8; const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE]; diff --git a/vm-virtio/src/queue.rs b/vm-virtio/src/queue.rs index 2789ee053..285692af6 100644 --- a/vm-virtio/src/queue.rs +++ b/vm-virtio/src/queue.rs @@ -13,7 +13,8 @@ pub mod testing { use std::mem; use virtio_queue::{Queue, QueueT, VirtqUsedElem}; - use vm_memory::{bitmap::AtomicBitmap, Address, Bytes, GuestAddress, GuestUsize}; + use vm_memory::bitmap::AtomicBitmap; + use vm_memory::{Address, Bytes, GuestAddress, GuestUsize}; type GuestMemoryMmap = vm_memory::GuestMemoryMmap; diff --git a/vmm/src/acpi.rs b/vmm/src/acpi.rs index 434fd16a5..2e45aaa5e 100644 --- a/vmm/src/acpi.rs +++ b/vmm/src/acpi.rs @@ -5,9 +5,11 @@ use std::sync::{Arc, Mutex}; use std::time::Instant; +use acpi_tables::rsdp::Rsdp; #[cfg(target_arch = "aarch64")] use acpi_tables::sdt::GenericAddress; -use acpi_tables::{rsdp::Rsdp, sdt::Sdt, Aml}; +use acpi_tables::sdt::Sdt; +use acpi_tables::Aml; #[cfg(target_arch = "aarch64")] use arch::aarch64::DeviceInfoForFdt; #[cfg(target_arch = "aarch64")] diff --git a/vmm/src/api/dbus/mod.rs b/vmm/src/api/dbus/mod.rs index 08f140863..8230a4f17 100644 --- a/vmm/src/api/dbus/mod.rs +++ b/vmm/src/api/dbus/mod.rs @@ -26,8 +26,7 @@ use crate::api::{ VmSendMigration, VmShutdown, VmSnapshot, VmmPing, VmmShutdown, }; use crate::seccomp_filters::{get_seccomp_filter, Thread}; -use crate::{Error as VmmError, Result as VmmResult}; -use crate::{NetConfig, VmConfig}; +use crate::{Error as VmmError, NetConfig, Result as VmmResult, VmConfig}; pub type DBusApiShutdownChannels = (oneshot::Sender<()>, oneshot::Receiver<()>); diff --git a/vmm/src/api/mod.rs b/vmm/src/api/mod.rs index 8a516ffb0..7d11cc4ac 100644 --- a/vmm/src/api/mod.rs +++ b/vmm/src/api/mod.rs @@ -45,8 +45,7 @@ use vmm_sys_util::eventfd::EventFd; #[cfg(feature = "dbus_api")] pub use self::dbus::start_dbus_thread; -pub use self::http::start_http_fd_thread; -pub use self::http::start_http_path_thread; +pub use self::http::{start_http_fd_thread, start_http_path_thread}; use crate::config::{ DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, UserDeviceConfig, VdpaConfig, VmConfig, VsockConfig, diff --git a/vmm/src/config.rs b/vmm/src/config.rs index f5f7f9c2a..a26d82561 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -4,10 +4,9 @@ // use std::collections::{BTreeSet, HashMap}; -use std::fmt; use std::path::PathBuf; -use std::result; use std::str::FromStr; +use std::{fmt, result}; use clap::ArgMatches; use option_parser::{ diff --git a/vmm/src/console_devices.rs b/vmm/src/console_devices.rs index dbe5813e9..6484e3945 100644 --- a/vmm/src/console_devices.rs +++ b/vmm/src/console_devices.rs @@ -10,27 +10,16 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause // -use std::fs::read_link; -use std::fs::File; -use std::fs::OpenOptions; -use std::io; +use std::fs::{read_link, File, OpenOptions}; use std::mem::zeroed; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::os::fd::RawFd; +use std::os::fd::{AsRawFd, FromRawFd, RawFd}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::net::UnixListener; use std::path::PathBuf; -use std::result; -use std::sync::Arc; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; +use std::{io, result}; -use libc::cfmakeraw; -use libc::isatty; -use libc::tcgetattr; -use libc::tcsetattr; -use libc::termios; -use libc::TCSANOW; +use libc::{cfmakeraw, isatty, tcgetattr, tcsetattr, termios, TCSANOW}; use thiserror::Error; use crate::sigwinch_listener::listen_for_sigwinch_on_tty; diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 82640c305..691b64630 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -21,14 +21,14 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier, Mutex}; use std::{cmp, io, result, thread}; -use acpi_tables::{aml, sdt::Sdt, Aml}; +use acpi_tables::sdt::Sdt; +use acpi_tables::{aml, Aml}; use anyhow::anyhow; #[cfg(all(target_arch = "aarch64", feature = "guest_debug"))] use arch::aarch64::regs; #[cfg(target_arch = "x86_64")] use arch::x86_64::get_x2apic_id; -use arch::EntryPoint; -use arch::NumaNodes; +use arch::{EntryPoint, NumaNodes}; #[cfg(target_arch = "aarch64")] use devices::gic::Gic; use devices::interrupt_controller::InterruptController; @@ -91,8 +91,7 @@ use crate::memory_manager::MemoryManager; use crate::seccomp_filters::{get_seccomp_filter, Thread}; #[cfg(target_arch = "x86_64")] use crate::vm::physical_bits; -use crate::GuestMemoryMmap; -use crate::CPU_MANAGER_SNAPSHOT_ID; +use crate::{GuestMemoryMmap, CPU_MANAGER_SNAPSHOT_ID}; #[cfg(all(target_arch = "aarch64", feature = "guest_debug"))] /// Extract the specified bits of a 64-bit integer. /// For example, to extrace 2 bits from offset 1 (zero based) of `6u64`, @@ -2806,8 +2805,7 @@ impl CpuElf64Writable for CpuManager { #[cfg(all(feature = "kvm", target_arch = "x86_64"))] #[cfg(test)] mod tests { - use arch::layout::BOOT_STACK_POINTER; - use arch::layout::ZERO_PAGE_START; + use arch::layout::{BOOT_STACK_POINTER, ZERO_PAGE_START}; use arch::x86_64::interrupts::*; use arch::x86_64::regs::*; use hypervisor::arch::x86::{FpuState, LapicState}; @@ -2947,7 +2945,8 @@ mod tests { mod tests { use std::mem; - use arch::{aarch64::regs, layout}; + use arch::aarch64::regs; + use arch::layout; use hypervisor::kvm::aarch64::is_system_register; use hypervisor::kvm::kvm_bindings::{ kvm_vcpu_init, user_pt_regs, KVM_REG_ARM64, KVM_REG_ARM64_SYSREG, KVM_REG_ARM_CORE, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 90f19cc6a..87bcfabe6 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -23,16 +23,19 @@ use std::time::Instant; use acpi_tables::sdt::GenericAddress; use acpi_tables::{aml, Aml}; use anyhow::anyhow; -use arch::layout; #[cfg(target_arch = "x86_64")] use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; -use arch::NumaNodes; +use arch::{layout, NumaNodes}; #[cfg(target_arch = "aarch64")] use arch::{DeviceType, MmioDeviceInfo}; +use block::async_io::DiskFile; +use block::fixed_vhd_sync::FixedVhdDiskSync; +use block::qcow_sync::QcowDiskSync; +use block::raw_async_aio::RawFileDiskAio; +use block::raw_sync::RawFileDiskSync; +use block::vhdx_sync::VhdxDiskSync; use block::{ - async_io::DiskFile, block_aio_is_supported, block_io_uring_is_supported, detect_image_type, - fixed_vhd_sync::FixedVhdDiskSync, qcow, qcow_sync::QcowDiskSync, raw_async_aio::RawFileDiskAio, - raw_sync::RawFileDiskSync, vhdx, vhdx_sync::VhdxDiskSync, ImageType, + block_aio_is_supported, block_io_uring_is_supported, detect_image_type, qcow, vhdx, ImageType, }; #[cfg(feature = "io_uring")] use block::{fixed_vhd_async::FixedVhdDiskAsync, raw_async::RawFileDisk}; @@ -40,15 +43,14 @@ use block::{fixed_vhd_async::FixedVhdDiskAsync, raw_async::RawFileDisk}; use devices::debug_console::DebugConsole; #[cfg(target_arch = "aarch64")] use devices::gic; +use devices::interrupt_controller::InterruptController; #[cfg(target_arch = "x86_64")] use devices::ioapic; #[cfg(target_arch = "aarch64")] use devices::legacy::Pl011; #[cfg(feature = "pvmemcontrol")] use devices::pvmemcontrol::{PvmemcontrolBusDevice, PvmemcontrolPciDevice}; -use devices::{ - interrupt_controller, interrupt_controller::InterruptController, AcpiNotificationFlags, -}; +use devices::{interrupt_controller, AcpiNotificationFlags}; use hypervisor::IoEventAddress; use libc::{ tcsetattr, termios, MAP_NORESERVE, MAP_PRIVATE, MAP_SHARED, O_TMPFILE, PROT_READ, PROT_WRITE, @@ -63,13 +65,12 @@ use seccompiler::SeccompAction; use serde::{Deserialize, Serialize}; use tracer::trace_scoped; use vfio_ioctls::{VfioContainer, VfioDevice, VfioDeviceFd}; -use virtio_devices::transport::VirtioTransport; -use virtio_devices::transport::{VirtioPciDevice, VirtioPciDeviceActivator}; +use virtio_devices::transport::{VirtioPciDevice, VirtioPciDeviceActivator, VirtioTransport}; use virtio_devices::vhost_user::VhostUserConfig; use virtio_devices::{ - AccessPlatformMapping, ActivateError, VdpaDmaMapping, VirtioMemMappingSource, + AccessPlatformMapping, ActivateError, Endpoint, IommuMapping, VdpaDmaMapping, + VirtioMemMappingSource, }; -use virtio_devices::{Endpoint, IommuMapping}; use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::interrupt::{ @@ -77,16 +78,15 @@ use vm_device::interrupt::{ }; use vm_device::{Bus, BusDevice, BusDeviceSync, Resource}; use vm_memory::guest_memory::FileOffset; -use vm_memory::GuestMemoryRegion; -use vm_memory::{Address, GuestAddress, GuestUsize, MmapRegion}; +use vm_memory::{Address, GuestAddress, GuestMemoryRegion, GuestUsize, MmapRegion}; #[cfg(target_arch = "x86_64")] use vm_memory::{GuestAddressSpace, GuestMemory}; +use vm_migration::protocol::MemoryRangeTable; use vm_migration::{ - protocol::MemoryRangeTable, snapshot_from_id, state_from_id, Migratable, MigratableError, - Pausable, Snapshot, SnapshotData, Snapshottable, Transportable, + snapshot_from_id, state_from_id, Migratable, MigratableError, Pausable, Snapshot, SnapshotData, + Snapshottable, Transportable, }; -use vm_virtio::AccessPlatform; -use vm_virtio::VirtioDeviceType; +use vm_virtio::{AccessPlatform, VirtioDeviceType}; use vmm_sys_util::eventfd::EventFd; #[cfg(target_arch = "x86_64")] use {devices::debug_console, devices::legacy::Serial}; @@ -98,15 +98,12 @@ use crate::config::{ use crate::console_devices::{ConsoleDeviceError, ConsoleInfo, ConsoleOutput}; use crate::cpu::{CpuManager, CPU_MANAGER_ACPI_SIZE}; use crate::device_tree::{DeviceNode, DeviceTree}; -use crate::interrupt::LegacyUserspaceInterruptManager; -use crate::interrupt::MsiInterruptManager; +use crate::interrupt::{LegacyUserspaceInterruptManager, MsiInterruptManager}; use crate::memory_manager::{Error as MemoryManagerError, MemoryManager, MEMORY_MANAGER_ACPI_SIZE}; use crate::pci_segment::PciSegment; use crate::serial_manager::{Error as SerialManagerError, SerialManager}; use crate::vm_config::DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT; -use crate::GuestRegionMmap; -use crate::PciDeviceInfo; -use crate::{device_node, DEVICE_MANAGER_SNAPSHOT_ID}; +use crate::{device_node, GuestRegionMmap, PciDeviceInfo, DEVICE_MANAGER_SNAPSHOT_ID}; #[cfg(target_arch = "aarch64")] const MMIO_LEN: u64 = 0x1000; diff --git a/vmm/src/gdb.rs b/vmm/src/gdb.rs index 1b06ec974..38305e95a 100644 --- a/vmm/src/gdb.rs +++ b/vmm/src/gdb.rs @@ -5,27 +5,22 @@ // // SPDX-License-Identifier: BSD-3-Clause -use std::{os::unix::net::UnixListener, sync::mpsc}; +use std::os::unix::net::UnixListener; +use std::sync::mpsc; -use gdbstub::{ - arch::Arch, - common::{Signal, Tid}, - conn::{Connection, ConnectionExt}, - stub::{run_blocking, DisconnectReason, MultiThreadStopReason}, - target::{ - ext::{ - base::{ - multithread::{ - MultiThreadBase, MultiThreadResume, MultiThreadResumeOps, - MultiThreadSingleStep, MultiThreadSingleStepOps, - }, - BaseOps, - }, - breakpoints::{Breakpoints, BreakpointsOps, HwBreakpoint, HwBreakpointOps}, - }, - Target, TargetError, TargetResult, - }, +use gdbstub::arch::Arch; +use gdbstub::common::{Signal, Tid}; +use gdbstub::conn::{Connection, ConnectionExt}; +use gdbstub::stub::{run_blocking, DisconnectReason, MultiThreadStopReason}; +use gdbstub::target::ext::base::multithread::{ + MultiThreadBase, MultiThreadResume, MultiThreadResumeOps, MultiThreadSingleStep, + MultiThreadSingleStepOps, }; +use gdbstub::target::ext::base::BaseOps; +use gdbstub::target::ext::breakpoints::{ + Breakpoints, BreakpointsOps, HwBreakpoint, HwBreakpointOps, +}; +use gdbstub::target::{Target, TargetError, TargetResult}; #[cfg(target_arch = "aarch64")] use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs; #[cfg(target_arch = "aarch64")] diff --git a/vmm/src/igvm/igvm_loader.rs b/vmm/src/igvm/igvm_loader.rs index 7ba957c23..16f4faaa6 100644 --- a/vmm/src/igvm/igvm_loader.rs +++ b/vmm/src/igvm/igvm_loader.rs @@ -4,13 +4,12 @@ // use std::collections::HashMap; use std::ffi::CString; -use std::io::Read; -use std::io::Seek; -use std::io::SeekFrom; +use std::io::{Read, Seek, SeekFrom}; use std::mem::size_of; use std::sync::{Arc, Mutex}; -use igvm::{snp_defs::SevVmsa, IgvmDirectiveHeader, IgvmFile, IgvmPlatformHeader, IsolationType}; +use igvm::snp_defs::SevVmsa; +use igvm::{IgvmDirectiveHeader, IgvmFile, IgvmPlatformHeader, IsolationType}; use igvm_defs::{ IgvmPageDataType, IgvmPlatformType, IGVM_VHS_PARAMETER, IGVM_VHS_PARAMETER_INSERT, }; @@ -21,9 +20,8 @@ use thiserror::Error; use zerocopy::AsBytes; use crate::cpu::CpuManager; -use crate::igvm::{ - loader::Loader, BootPageAcceptance, IgvmLoadedInfo, StartupMemoryType, HV_PAGE_SIZE, -}; +use crate::igvm::loader::Loader; +use crate::igvm::{BootPageAcceptance, IgvmLoadedInfo, StartupMemoryType, HV_PAGE_SIZE}; use crate::memory_manager::MemoryManager; #[cfg(feature = "sev_snp")] use crate::GuestMemoryMmap; diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 6f1c1302d..969bb1613 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -10,18 +10,16 @@ extern crate log; use std::collections::HashMap; use std::fs::File; -use std::io; use std::io::{stdout, Read, Write}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; -use std::os::unix::net::UnixListener; -use std::os::unix::net::UnixStream; +use std::os::unix::net::{UnixListener, UnixStream}; use std::panic::AssertUnwindSafe; use std::path::PathBuf; use std::rc::Rc; use std::sync::mpsc::{Receiver, RecvError, SendError, Sender}; use std::sync::{Arc, Mutex}; use std::time::Instant; -use std::{result, thread}; +use std::{io, result, thread}; use anyhow::anyhow; #[cfg(feature = "dbus_api")] @@ -40,8 +38,8 @@ use thiserror::Error; use tracer::trace_scoped; use vm_memory::bitmap::AtomicBitmap; use vm_memory::{ReadVolatile, WriteVolatile}; -use vm_migration::{protocol::*, Migratable}; -use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; +use vm_migration::protocol::*; +use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::signal::unblock_signal; use vmm_sys_util::sock_ctrl_msg::ScmSocket; diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index 1e94af64d..8d7ea771f 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -12,9 +12,8 @@ use std::ops::{BitAnd, Deref, Not, Sub}; use std::os::fd::AsFd; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::PathBuf; -use std::result; use std::sync::{Arc, Barrier, Mutex}; -use std::{ffi, thread}; +use std::{ffi, result, thread}; use acpi_tables::{aml, Aml}; use anyhow::anyhow; @@ -37,14 +36,14 @@ use vm_allocator::{AddressAllocator, SystemAllocator}; use vm_device::BusDevice; use vm_memory::bitmap::AtomicBitmap; use vm_memory::guest_memory::FileOffset; +use vm_memory::mmap::MmapRegionError; use vm_memory::{ - mmap::MmapRegionError, Address, Error as MmapError, GuestAddress, GuestAddressSpace, - GuestMemory, GuestMemoryAtomic, GuestMemoryError, GuestMemoryRegion, GuestUsize, MmapRegion, - ReadVolatile, + Address, Error as MmapError, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, + GuestMemoryError, GuestMemoryRegion, GuestUsize, MmapRegion, ReadVolatile, }; +use vm_migration::protocol::{MemoryRange, MemoryRangeTable}; use vm_migration::{ - protocol::MemoryRange, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, - Snapshot, SnapshotData, Snapshottable, Transportable, + Migratable, MigratableError, Pausable, Snapshot, SnapshotData, Snapshottable, Transportable, }; #[cfg(target_arch = "x86_64")] @@ -55,8 +54,7 @@ use crate::coredump::{ CoredumpMemoryRegion, CoredumpMemoryRegions, DumpState, GuestDebuggableError, }; use crate::migration::url_to_path; -use crate::MEMORY_MANAGER_SNAPSHOT_ID; -use crate::{GuestMemoryMmap, GuestRegionMmap}; +use crate::{GuestMemoryMmap, GuestRegionMmap, MEMORY_MANAGER_SNAPSHOT_ID}; pub const MEMORY_MANAGER_ACPI_SIZE: usize = 0x18; diff --git a/vmm/src/migration.rs b/vmm/src/migration.rs index 4edd71da2..cb549ea4e 100644 --- a/vmm/src/migration.rs +++ b/vmm/src/migration.rs @@ -9,9 +9,10 @@ use std::path::PathBuf; use anyhow::anyhow; use vm_migration::{MigratableError, Snapshot}; +use crate::config::VmConfig; #[cfg(all(target_arch = "x86_64", feature = "guest_debug"))] use crate::coredump::GuestDebuggableError; -use crate::{config::VmConfig, vm::VmSnapshot}; +use crate::vm::VmSnapshot; pub const SNAPSHOT_STATE_FILE: &str = "state.json"; pub const SNAPSHOT_CONFIG_FILE: &str = "config.json"; diff --git a/vmm/src/seccomp_filters.rs b/vmm/src/seccomp_filters.rs index 17fc93d14..47dbaf21a 100644 --- a/vmm/src/seccomp_filters.rs +++ b/vmm/src/seccomp_filters.rs @@ -5,8 +5,9 @@ // SPDX-License-Identifier: Apache-2.0 use hypervisor::HypervisorType; +use seccompiler::SeccompCmpOp::Eq; use seccompiler::{ - BackendError, BpfProgram, Error, SeccompAction, SeccompCmpArgLen as ArgLen, SeccompCmpOp::Eq, + BackendError, BpfProgram, Error, SeccompAction, SeccompCmpArgLen as ArgLen, SeccompCondition as Cond, SeccompFilter, SeccompRule, }; diff --git a/vmm/src/sigwinch_listener.rs b/vmm/src/sigwinch_listener.rs index ac87cf27e..4d7aebdca 100644 --- a/vmm/src/sigwinch_listener.rs +++ b/vmm/src/sigwinch_listener.rs @@ -6,8 +6,7 @@ use std::collections::BTreeSet; use std::fs::{read_dir, File}; use std::io::{self, ErrorKind, Read, Write}; use std::iter::once; -use std::mem::size_of; -use std::mem::MaybeUninit; +use std::mem::{size_of, MaybeUninit}; use std::os::unix::prelude::*; use std::process::exit; use std::ptr::null_mut; diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 00fe42af0..304073919 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -11,9 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause // -use std::cmp; -use std::collections::BTreeMap; -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use std::fs::{File, OpenOptions}; use std::io::{self, Seek, SeekFrom, Write}; #[cfg(all(target_arch = "x86_64", feature = "guest_debug"))] @@ -23,18 +21,16 @@ use std::ops::Deref; use std::os::unix::net::UnixStream; use std::sync::{Arc, Mutex, RwLock}; use std::time::Instant; -use std::{result, str, thread}; +use std::{cmp, result, str, thread}; use anyhow::anyhow; -use arch::get_host_cpu_phys_bits; #[cfg(target_arch = "x86_64")] use arch::layout::{KVM_IDENTITY_MAP_START, KVM_TSS_START}; #[cfg(feature = "tdx")] use arch::x86_64::tdx::TdvfSection; -use arch::EntryPoint; #[cfg(target_arch = "aarch64")] use arch::PciSpaceInfo; -use arch::{NumaNode, NumaNodes}; +use arch::{get_host_cpu_phys_bits, EntryPoint, NumaNode, NumaNodes}; #[cfg(target_arch = "aarch64")] use devices::interrupt_controller; use devices::AcpiNotificationFlags; @@ -64,25 +60,23 @@ use vm_memory::{Address, ByteValued, GuestMemoryRegion, ReadVolatile}; use vm_memory::{ Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, WriteVolatile, }; -use vm_migration::protocol::{Request, Response}; +use vm_migration::protocol::{MemoryRangeTable, Request, Response}; use vm_migration::{ - protocol::MemoryRangeTable, snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot, - Snapshottable, Transportable, + snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, }; use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::sock_ctrl_msg::ScmSocket; use crate::config::{ - add_to_config, DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, - UserDeviceConfig, ValidationError, VdpaConfig, VmConfig, VsockConfig, + add_to_config, DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, NumaConfig, + PayloadConfig, PmemConfig, UserDeviceConfig, ValidationError, VdpaConfig, VmConfig, + VsockConfig, }; -use crate::config::{NumaConfig, PayloadConfig}; use crate::console_devices::{ConsoleDeviceError, ConsoleInfo}; #[cfg(all(target_arch = "x86_64", feature = "guest_debug"))] use crate::coredump::{ CpuElf64Writable, DumpState, Elf64Writable, GuestDebuggable, GuestDebuggableError, NoteDescType, }; -use crate::cpu; use crate::device_manager::{DeviceManager, DeviceManagerError}; use crate::device_tree::DeviceTree; #[cfg(feature = "guest_debug")] @@ -98,9 +92,9 @@ use crate::migration::get_vm_snapshot; #[cfg(all(target_arch = "x86_64", feature = "guest_debug"))] use crate::migration::url_to_file; use crate::migration::{url_to_path, SNAPSHOT_CONFIG_FILE, SNAPSHOT_STATE_FILE}; -use crate::GuestMemoryMmap; use crate::{ - PciDeviceInfo, CPU_MANAGER_SNAPSHOT_ID, DEVICE_MANAGER_SNAPSHOT_ID, MEMORY_MANAGER_SNAPSHOT_ID, + cpu, GuestMemoryMmap, PciDeviceInfo, CPU_MANAGER_SNAPSHOT_ID, DEVICE_MANAGER_SNAPSHOT_ID, + MEMORY_MANAGER_SNAPSHOT_ID, }; /// Errors associated with VM management diff --git a/vmm/src/vm_config.rs b/vmm/src/vm_config.rs index 408b0ca0b..e74fbc1d6 100644 --- a/vmm/src/vm_config.rs +++ b/vmm/src/vm_config.rs @@ -2,13 +2,16 @@ // // SPDX-License-Identifier: Apache-2.0 // -use std::{fs, net::Ipv4Addr, path::PathBuf, result}; +use std::net::Ipv4Addr; +use std::path::PathBuf; +use std::{fs, result}; use net_util::MacAddr; use serde::{Deserialize, Serialize}; use virtio_devices::RateLimiterConfig; -use crate::{landlock::LandlockError, Landlock}; +use crate::landlock::LandlockError; +use crate::Landlock; pub type LandlockResult = result::Result;