Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format imports #202

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion alioth/src/arch/aarch64/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::c_enum;
use bitfield::bitfield;
use bitflags::bitflags;

use crate::c_enum;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Reg {
X0,
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/arch/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ mod aarch64;
mod x86_64;

#[cfg(target_arch = "aarch64")]
pub use aarch64::*;
pub use self::aarch64::*;
#[cfg(target_arch = "x86_64")]
pub use x86_64::*;
pub use self::x86_64::*;
4 changes: 2 additions & 2 deletions alioth/src/board/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ use crate::vfio::container::Container;
use crate::vfio::iommu::Ioas;

#[cfg(target_arch = "aarch64")]
pub(crate) use aarch64::ArchBoard;
pub(crate) use self::aarch64::ArchBoard;
#[cfg(target_arch = "x86_64")]
pub(crate) use x86_64::ArchBoard;
pub(crate) use self::x86_64::ArchBoard;

#[trace_error]
#[derive(Snafu, DebugTrace)]
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/device/fw_cfg/fw_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#[cfg(target_arch = "x86_64")]
pub mod acpi;

use core::fmt;
use std::ffi::CString;
use std::fmt;
use std::fs::File;
use std::io::{ErrorKind, Read, Result, Seek, SeekFrom};
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -51,7 +51,7 @@ use crate::mem::mapped::RamBus;
use crate::mem::{MemRegionEntry, MemRegionType};

#[cfg(target_arch = "x86_64")]
use acpi::create_acpi_loader;
use self::acpi::create_acpi_loader;

pub const SELECTOR_WR: u16 = 1 << 14;

Expand Down
4 changes: 2 additions & 2 deletions alioth/src/firmware/acpi/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use crate::arch::layout::{
};
use crate::utils::wrapping_sum;

use bindings::{
use self::bindings::{
AcpiGenericAddress, AcpiMadtIoApic, AcpiMadtLocalX2apic, AcpiMcfgAllocation,
AcpiSubtableHeader, AcpiTableFadt, AcpiTableHeader, AcpiTableMadt, AcpiTableMcfg1,
AcpiTableRsdp, AcpiTableXsdt3, FADT_MAJOR_VERSION, FADT_MINOR_VERSION, MADT_IO_APIC,
MADT_LOCAL_X2APIC, MADT_REVISION, MCFG_REVISION, RSDP_REVISION, SIG_FADT, SIG_MADT, SIG_MCFG,
SIG_RSDP, SIG_XSDT, XSDT_REVISION,
};
use reg::FADT_RESET_VAL;
use self::reg::FADT_RESET_VAL;

const OEM_ID: [u8; 6] = *b"ALIOTH";

Expand Down
4 changes: 2 additions & 2 deletions alioth/src/hv/hv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ use crate::arch::sev::{SevPolicy, SnpPageType, SnpPolicy};
use crate::errors::{trace_error, DebugTrace};

#[cfg(target_os = "macos")]
pub use hvf::Hvf;
pub use self::hvf::Hvf;
#[cfg(target_os = "linux")]
pub use kvm::{Kvm, KvmConfig, KvmError};
pub use self::kvm::{Kvm, KvmConfig, KvmError};

#[trace_error]
#[derive(Snafu, DebugTrace)]
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/hv/hvf/hvf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::ptr::null_mut;

use bindings::hv_vm_create;
use parking_lot::Mutex;
use snafu::ResultExt;

use crate::hv::{error, Hypervisor, Result, VmConfig};

use vm::HvfVm;
use self::bindings::hv_vm_create;
use self::vm::HvfVm;

#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
Expand Down
14 changes: 7 additions & 7 deletions alioth/src/hv/kvm/kvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use std::ptr::null_mut;
use std::sync::atomic::AtomicU32;
use std::sync::Arc;

use libc::SIGRTMIN;
use parking_lot::lock_api::RwLock;
use parking_lot::Mutex;
use serde::Deserialize;
Expand All @@ -54,15 +55,14 @@ use crate::ffi;
use crate::hv::{error, Hypervisor, MemMapOption, Result, VmConfig};

#[cfg(target_arch = "aarch64")]
use bindings::KvmDevType;
use bindings::KVM_API_VERSION;
use self::bindings::KvmDevType;
use self::bindings::KVM_API_VERSION;
#[cfg(target_arch = "x86_64")]
use bindings::{KvmCpuid2, KvmCpuid2Flag, KvmCpuidEntry2, KVM_MAX_CPUID_ENTRIES};
use self::bindings::{KvmCpuid2, KvmCpuid2Flag, KvmCpuidEntry2, KVM_MAX_CPUID_ENTRIES};
#[cfg(target_arch = "x86_64")]
use ioctls::kvm_get_supported_cpuid;
use ioctls::{kvm_create_vm, kvm_get_api_version, kvm_get_vcpu_mmap_size};
use libc::SIGRTMIN;
use vm::{KvmVm, VmInner};
use self::ioctls::kvm_get_supported_cpuid;
use self::ioctls::{kvm_create_vm, kvm_get_api_version, kvm_get_vcpu_mmap_size};
use self::vm::{KvmVm, VmInner};

#[trace_error]
#[derive(DebugTrace, Snafu)]
Expand Down
5 changes: 3 additions & 2 deletions alioth/src/hv/kvm/sev/sev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ use std::fs::File;
use std::os::fd::{AsFd, BorrowedFd, OwnedFd};
use std::path::Path;

use snafu::ResultExt;

use crate::hv::kvm::kvm_error;
use crate::hv::Result;
use crate::ioctl_writeread;

use bindings::{SevIssueCmd, SEV_RET_SUCCESS};
use snafu::ResultExt;
use self::bindings::{SevIssueCmd, SEV_RET_SUCCESS};

const SEV_IOC_TYPE: u8 = b'S';

Expand Down
2 changes: 1 addition & 1 deletion alioth/src/hv/kvm/vcpu/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ impl KvmVcpu {

#[cfg(test)]
mod test {
use assert_matches::assert_matches;
use std::mem::size_of_val;
use std::ptr::null_mut;

use assert_matches::assert_matches;
use libc::{mmap, MAP_ANONYMOUS, MAP_FAILED, MAP_SHARED, PROT_EXEC, PROT_READ, PROT_WRITE};

use crate::arch::msr::Efer;
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/hv/kvm/vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::hv::{
};

#[cfg(target_arch = "x86_64")]
pub use x86_64::VmArch;
pub use self::x86_64::VmArch;

#[derive(Debug)]
pub(super) struct VmInner {
Expand Down Expand Up @@ -756,9 +756,9 @@ impl Vm for KvmVm {

#[cfg(test)]
mod test {
use assert_matches::assert_matches;
use std::ptr::null_mut;

use assert_matches::assert_matches;
use libc::{mmap, MAP_ANONYMOUS, MAP_FAILED, MAP_PRIVATE, PROT_EXEC, PROT_READ, PROT_WRITE};

use super::*;
Expand Down
3 changes: 1 addition & 2 deletions alioth/src/hv/kvm/vmentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
// limitations under the License.

use crate::hv::kvm::bindings::{KvmExit, KvmExitIo};

use super::vcpu::KvmVcpu;
use crate::hv::kvm::vcpu::KvmVcpu;

impl KvmVcpu {
#[cfg(target_endian = "little")]
Expand Down
3 changes: 1 addition & 2 deletions alioth/src/hv/kvm/vmexit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
use crate::hv::kvm::bindings::{
KvmExitIo, KvmMapGpaRangeFlag, KvmSystemEvent, KVM_HC_MAP_GPA_RANGE,
};
use crate::hv::kvm::vcpu::KvmVcpu;
use crate::hv::{Error, VmExit};

use super::vcpu::KvmVcpu;

impl KvmVcpu {
#[cfg(target_endian = "little")]
pub(super) fn handle_mmio(&mut self) -> Result<VmExit, Error> {
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/loader/firmware/firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ mod aarch64;
mod x86_64;

#[cfg(target_arch = "aarch64")]
pub use aarch64::load;
pub use self::aarch64::load;
#[cfg(target_arch = "x86_64")]
pub use x86_64::load;
pub use self::x86_64::load;
4 changes: 2 additions & 2 deletions alioth/src/loader/linux/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub mod bootparams;
mod x86_64;

#[cfg(target_arch = "aarch64")]
pub use aarch64::load;
pub use self::aarch64::load;
#[cfg(target_arch = "x86_64")]
pub use x86_64::load;
pub use self::x86_64::load;
12 changes: 6 additions & 6 deletions alioth/src/loader/linux/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ use std::io::{BufReader, Read, Seek, SeekFrom};
use std::mem::{size_of, size_of_val};
use std::path::Path;

use crate::arch::msr::Efer;
use crate::arch::paging::Entry;
use crate::arch::reg::{
Cr0, Cr4, DtReg, DtRegVal, Reg, Rflags, SReg, SegAccess, SegReg, SegRegVal,
};
use crate::mem::mapped::RamBus;
use snafu::ResultExt;
use zerocopy::{FromZeros, IntoBytes};

use crate::arch::layout::{
BOOT_GDT_START, BOOT_PAGING_START, EBDA_START, KERNEL_CMD_LINE_LIMIT, KERNEL_CMD_LINE_START,
KERNEL_IMAGE_START, LINUX_BOOT_PARAMS_START,
};
use crate::arch::msr::Efer;
use crate::arch::paging::Entry;
use crate::arch::reg::{
Cr0, Cr4, DtReg, DtRegVal, Reg, Rflags, SReg, SegAccess, SegReg, SegRegVal,
};
use crate::mem::mapped::RamBus;
use crate::mem::{MemRegionEntry, MemRegionType};

use crate::loader::linux::bootparams::{
Expand Down
18 changes: 9 additions & 9 deletions alioth/src/loader/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod elf;
#[path = "firmware/firmware.rs"]
pub mod firmware;
#[path = "linux/linux.rs"]
pub mod linux;
#[cfg(target_arch = "x86_64")]
#[path = "xen/xen.rs"]
pub mod xen;

use std::ops::Range;
use std::path::PathBuf;

Expand All @@ -23,15 +32,6 @@ use crate::arch::reg::{Reg, SReg};
use crate::errors::{trace_error, DebugTrace};
use crate::mem::{MemRegionEntry, MemRegionType};

pub mod elf;
#[path = "firmware/firmware.rs"]
pub mod firmware;
#[path = "linux/linux.rs"]
pub mod linux;
#[cfg(target_arch = "x86_64")]
#[path = "xen/xen.rs"]
pub mod xen;

#[derive(Debug)]
pub struct Payload {
pub executable: PathBuf,
Expand Down
1 change: 1 addition & 0 deletions alioth/src/loader/xen/start_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use zerocopy::{FromZeros, Immutable, IntoBytes};

pub const XEN_HVM_START_MAGIC_VALUE: u32 = 0x336ec578;
Expand Down
6 changes: 3 additions & 3 deletions alioth/src/loader/xen/xen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod start_info;

use std::fs::File;
use std::io::{BufReader, Read, Seek, SeekFrom};
use std::mem::{offset_of, size_of, size_of_val};
Expand All @@ -37,9 +39,7 @@ use crate::loader::{error, search_initramfs_address, InitState, Result};
use crate::mem::mapped::RamBus;
use crate::mem::{MemRegionEntry, MemRegionType};

pub mod start_info;

use start_info::{HvmMemmapTableEntry, HvmModlistEntry, HvmStartInfo};
use self::start_info::{HvmMemmapTableEntry, HvmModlistEntry, HvmStartInfo};

pub const XEN_ELFNOTE_PHYS32_ENTRY: u32 = 18;

Expand Down
2 changes: 1 addition & 1 deletion alioth/src/mem/mapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ impl RamBus {

#[cfg(test)]
mod test {
use assert_matches::assert_matches;
use std::io::{Read, Write};
use std::mem::size_of;

use assert_matches::assert_matches;
use libc::{PROT_READ, PROT_WRITE};
use zerocopy::{FromBytes, Immutable, IntoBytes};

Expand Down
14 changes: 7 additions & 7 deletions alioth/src/mem/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod addressable;
pub mod emulated;
pub mod mapped;

use std::any::type_name;
use std::fmt::Debug;
use std::sync::Arc;
Expand All @@ -24,13 +28,9 @@ use snafu::Snafu;
use crate::errors::{trace_error, DebugTrace};
use crate::hv::{MemMapOption, VmEntry, VmMemory};

pub mod addressable;
pub mod emulated;
pub mod mapped;

use addressable::{Addressable, SlotBackend};
use emulated::{Action, MmioBus, MmioRange};
use mapped::{ArcMemPages, Ram, RamBus};
use self::addressable::{Addressable, SlotBackend};
use self::emulated::{Action, MmioBus, MmioRange};
use self::mapped::{ArcMemPages, Ram, RamBus};

#[trace_error]
#[derive(Snafu, DebugTrace)]
Expand Down
14 changes: 7 additions & 7 deletions alioth/src/pci/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod bus;
pub mod cap;
pub mod config;
pub mod host_bridge;
pub mod segment;

use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;

Expand All @@ -23,13 +29,7 @@ use crate::errors::{trace_error, DebugTrace};
use crate::mem;
use crate::mem::{IoRegion, MemRegion, MemRegionCallback};

pub mod bus;
pub mod cap;
pub mod config;
pub mod host_bridge;
pub mod segment;

use config::{HeaderData, PciConfig, BAR_MEM64};
use self::config::{HeaderData, PciConfig, BAR_MEM64};

bitfield! {
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::atomic::{AtomicU64, Ordering};

pub mod endian;
#[cfg(target_os = "linux")]
pub mod ioctls;

use std::sync::atomic::{AtomicU64, Ordering};

pub fn truncate_u64(val: u64, size: u64) -> u64 {
val & u64::MAX >> (64 - (size << 3))
}
Expand Down
Loading
Loading