build: treewide: fmt for edition 2024

`cargo +nightly fmt`

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-08-12 12:59:23 +02:00
committed by Bo Chen
parent 061351d82d
commit 363273111a
121 changed files with 781 additions and 663 deletions

View File

@@ -5,16 +5,16 @@
use std::sync::{Arc, Mutex};
use std::time::Instant;
use acpi_tables::Aml;
use acpi_tables::rsdp::Rsdp;
#[cfg(target_arch = "aarch64")]
use acpi_tables::sdt::GenericAddress;
use acpi_tables::sdt::Sdt;
use acpi_tables::Aml;
#[cfg(target_arch = "aarch64")]
use arch::aarch64::DeviceInfoForFdt;
#[cfg(target_arch = "aarch64")]
use arch::DeviceType;
use arch::NumaNodes;
#[cfg(target_arch = "aarch64")]
use arch::aarch64::DeviceInfoForFdt;
use bitflags::bitflags;
use pci::PciBdf;
use tracer::trace_scoped;

View File

@@ -3,14 +3,14 @@
// SPDX-License-Identifier: Apache-2.0
//
use std::panic::AssertUnwindSafe;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::sync::mpsc::Sender;
use std::thread;
use futures::channel::oneshot;
use futures::{executor, FutureExt};
use futures::{FutureExt, executor};
use hypervisor::HypervisorType;
use seccompiler::{apply_filter, SeccompAction};
use seccompiler::{SeccompAction, apply_filter};
use vmm_sys_util::eventfd::EventFd;
use zbus::connection::Builder;
use zbus::fdo::{self, Result};
@@ -26,7 +26,7 @@ use crate::api::{
VmReceiveMigration, VmRemoveDevice, VmResize, VmResizeZone, VmRestore, VmResume,
VmSendMigration, VmShutdown, VmSnapshot, VmmPing, VmmShutdown,
};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::seccomp_filters::{Thread, get_seccomp_filter};
use crate::{Error as VmmError, NetConfig, Result as VmmResult, VmConfig};
pub type DBusApiShutdownChannels = (oneshot::Sender<()>, oneshot::Receiver<()>);

View File

@@ -11,9 +11,9 @@ use std::sync::mpsc::Sender;
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use vmm_sys_util::eventfd::EventFd;
use crate::api::http::{error_response, EndpointHandler, HttpError};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use crate::api::VmCoredump;
use crate::api::http::{EndpointHandler, HttpError, error_response};
use crate::api::{
AddDisk, ApiAction, ApiError, ApiRequest, NetConfig, VmAddDevice, VmAddFs, VmAddNet, VmAddPmem,
VmAddUserDevice, VmAddVdpa, VmAddVsock, VmBoot, VmConfig, VmCounters, VmDelete, VmNmi, VmPause,

View File

@@ -10,15 +10,15 @@ use std::os::unix::io::{IntoRawFd, RawFd};
use std::os::unix::net::UnixListener;
use std::panic::AssertUnwindSafe;
use std::path::PathBuf;
use std::sync::mpsc::Sender;
use std::sync::LazyLock;
use std::sync::mpsc::Sender;
use std::thread;
use hypervisor::HypervisorType;
use micro_http::{
Body, HttpServer, MediaType, Method, Request, Response, ServerError, StatusCode, Version,
};
use seccompiler::{apply_filter, SeccompAction};
use seccompiler::{SeccompAction, apply_filter};
use serde_json::Error as SerdeError;
use thiserror::Error;
use vmm_sys_util::eventfd::EventFd;
@@ -33,7 +33,7 @@ use crate::api::{
VmSendMigration, VmShutdown, VmSnapshot,
};
use crate::landlock::Landlock;
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::seccomp_filters::{Thread, get_seccomp_filter};
use crate::{Error as VmmError, Result};
pub mod http_endpoint;

View File

@@ -34,7 +34,7 @@ pub mod dbus;
pub mod http;
use std::io;
use std::sync::mpsc::{channel, RecvError, SendError, Sender};
use std::sync::mpsc::{RecvError, SendError, Sender, channel};
use micro_http::Body;
use serde::{Deserialize, Serialize};
@@ -45,6 +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, start_http_path_thread};
use crate::Error as VmmError;
use crate::config::RestoreConfig;
use crate::device_tree::DeviceTree;
use crate::vm::{Error as VmError, VmState};
@@ -52,7 +53,6 @@ use crate::vm_config::{
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig, VdpaConfig,
VmConfig, VsockConfig,
};
use crate::Error as VmmError;
/// API errors are sent back from the VMM API server through the ApiResponse.
#[derive(Error, Debug)]

View File

@@ -1,7 +1,7 @@
// Copyright 2021 Alyssa Ross <hi@alyssa.is>
// SPDX-License-Identifier: Apache-2.0
use libc::{c_long, size_t, syscall, SYS_clone3};
use libc::{SYS_clone3, c_long, size_t, syscall};
pub const CLONE_CLEAR_SIGHAND: u64 = 0x100000000;

View File

@@ -270,7 +270,9 @@ pub enum ValidationError {
#[error("Invalid PCI segment aperture weight: {0}")]
InvalidPciSegmentApertureWeight(u32),
/// Invalid IOMMU address width in bits
#[error("IOMMU address width in bits ({0}) should be less than or equal to {MAX_IOMMU_ADDRESS_WIDTH_BITS}")]
#[error(
"IOMMU address width in bits ({0}) should be less than or equal to {MAX_IOMMU_ADDRESS_WIDTH_BITS}"
)]
InvalidIommuAddressWidthBits(u8),
/// Balloon too big
#[error("Ballon size ({0}) greater than RAM ({1})")]
@@ -1536,8 +1538,7 @@ impl RngConfig {
}
impl BalloonConfig {
pub const SYNTAX: &'static str =
"Balloon parameters \"size=<balloon_size>,deflate_on_oom=on|off,\
pub const SYNTAX: &'static str = "Balloon parameters \"size=<balloon_size>,deflate_on_oom=on|off,\
free_page_reporting=on|off\"";
pub fn parse(balloon: &str) -> Result<Self> {
@@ -1911,8 +1912,7 @@ impl DebugConsoleConfig {
}
impl DeviceConfig {
pub const SYNTAX: &'static str =
"Direct device assignment parameters \"path=<device_path>,iommu=on|off,id=<device_id>,pci_segment=<segment_id>\"";
pub const SYNTAX: &'static str = "Direct device assignment parameters \"path=<device_path>,iommu=on|off,id=<device_id>,pci_segment=<segment_id>\"";
pub fn parse(device: &str) -> Result<Self> {
let mut parser = OptionParser::new();
@@ -2206,7 +2206,9 @@ where
S: serde::Serializer,
{
if let Some(x) = x {
warn!("'RestoredNetConfig' contains FDs that can't be serialized correctly. Serializing them as invalid FDs.");
warn!(
"'RestoredNetConfig' contains FDs that can't be serialized correctly. Serializing them as invalid FDs."
);
let invalid_fds = vec![-1; x.len()];
s.serialize_some(&invalid_fds)
} else {
@@ -2222,7 +2224,9 @@ where
{
let invalid_fds: Option<Vec<i32>> = Option::deserialize(d)?;
if let Some(invalid_fds) = invalid_fds {
warn!("'RestoredNetConfig' contains FDs that can't be deserialized correctly. Deserializing them as invalid FDs.");
warn!(
"'RestoredNetConfig' contains FDs that can't be deserialized correctly. Deserializing them as invalid FDs."
);
Ok(Some(vec![-1; invalid_fds.len()]))
} else {
Ok(None)
@@ -3556,7 +3560,9 @@ mod tests {
);
assert_eq!(
NetConfig::parse("mac=de:ad:be:ef:12:34,host_mac=12:34:de:ad:be:ef,num_queues=4,queue_size=1024,iommu=on")?,
NetConfig::parse(
"mac=de:ad:be:ef:12:34,host_mac=12:34:de:ad:be:ef,num_queues=4,queue_size=1024,iommu=on"
)?,
NetConfig {
num_queues: 4,
queue_size: 1024,
@@ -4814,18 +4820,19 @@ mod tests {
)?,
FwCfgConfig {
items: Some(FwCfgItemList {
item_list: vec![FwCfgItem {
name: "opt/org.test/fw_cfg_test_item".to_string(),
file: PathBuf::from("/tmp/fw_cfg_test_item"),
},
FwCfgItem {
name: "opt/org.test/fw_cfg_test_item2".to_string(),
file: PathBuf::from("/tmp/fw_cfg_test_item2"),
}]
item_list: vec![
FwCfgItem {
name: "opt/org.test/fw_cfg_test_item".to_string(),
file: PathBuf::from("/tmp/fw_cfg_test_item"),
},
FwCfgItem {
name: "opt/org.test/fw_cfg_test_item2".to_string(),
file: PathBuf::from("/tmp/fw_cfg_test_item2"),
}
]
}),
..Default::default()
},
},
);
Ok(())
}

View File

@@ -10,7 +10,7 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
//
use std::fs::{read_link, File, OpenOptions};
use std::fs::{File, OpenOptions, read_link};
use std::mem::zeroed;
use std::os::fd::{AsRawFd, FromRawFd, RawFd};
use std::os::unix::fs::OpenOptionsExt;
@@ -19,12 +19,12 @@ use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::{io, result};
use libc::{cfmakeraw, isatty, tcgetattr, tcsetattr, termios, TCSANOW};
use libc::{TCSANOW, cfmakeraw, isatty, tcgetattr, tcsetattr, termios};
use thiserror::Error;
use crate::Vmm;
use crate::sigwinch_listener::listen_for_sigwinch_on_tty;
use crate::vm_config::ConsoleOutputMode;
use crate::Vmm;
const TIOCSPTLCK: libc::c_int = 0x4004_5431;
const TIOCGPTPEER: libc::c_int = 0x5441;
@@ -225,7 +225,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
ConsoleOutput::Tty(Arc::new(stdout))
}
ConsoleOutputMode::Socket => {
return Err(ConsoleDeviceError::NoSocketOptionSupportForConsoleDevice)
return Err(ConsoleDeviceError::NoSocketOptionSupportForConsoleDevice);
}
ConsoleOutputMode::Null => ConsoleOutput::Null,
ConsoleOutputMode::Off => ConsoleOutput::Off,
@@ -288,7 +288,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
ConsoleOutput::Tty(Arc::new(out))
}
ConsoleOutputMode::Socket => {
return Err(ConsoleDeviceError::NoSocketOptionSupportForConsoleDevice)
return Err(ConsoleDeviceError::NoSocketOptionSupportForConsoleDevice);
}
ConsoleOutputMode::Null => ConsoleOutput::Null,
ConsoleOutputMode::Off => ConsoleOutput::Off,

View File

@@ -23,7 +23,7 @@ use std::{cmp, io, result, thread};
#[cfg(not(target_arch = "riscv64"))]
use acpi_tables::sdt::Sdt;
use acpi_tables::{aml, Aml};
use acpi_tables::{Aml, aml};
use anyhow::anyhow;
#[cfg(target_arch = "x86_64")]
use arch::x86_64::get_x2apic_id;
@@ -34,30 +34,30 @@ use devices::interrupt_controller::InterruptController;
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use gdbstub_arch::x86::reg::{X86SegmentRegs, X86_64CoreRegs as CoreRegs};
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
use hypervisor::arch::aarch64::regs::{ID_AA64MMFR0_EL1, TCR_EL1, TTBR1_EL1};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::msr_index;
#[cfg(target_arch = "x86_64")]
use hypervisor::arch::x86::CpuIdEntry;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::MsrEntry;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::SpecialRegisters;
#[cfg(feature = "tdx")]
use hypervisor::kvm::{TdxExitDetails, TdxExitStatus};
use gdbstub_arch::x86::reg::{X86_64CoreRegs as CoreRegs, X86SegmentRegs};
#[cfg(target_arch = "x86_64")]
use hypervisor::CpuVendor;
#[cfg(feature = "kvm")]
use hypervisor::HypervisorType;
#[cfg(feature = "guest_debug")]
use hypervisor::StandardRegisters;
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
use hypervisor::arch::aarch64::regs::{ID_AA64MMFR0_EL1, TCR_EL1, TTBR1_EL1};
#[cfg(target_arch = "x86_64")]
use hypervisor::arch::x86::CpuIdEntry;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::MsrEntry;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::SpecialRegisters;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::msr_index;
#[cfg(feature = "tdx")]
use hypervisor::kvm::{TdxExitDetails, TdxExitStatus};
use hypervisor::{CpuState, HypervisorCpuError, VmExit, VmOps};
use libc::{c_void, siginfo_t};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use linux_loader::elf::Elf64_Nhdr;
use seccompiler::{apply_filter, SeccompAction};
use seccompiler::{SeccompAction, apply_filter};
use thiserror::Error;
use tracer::trace_scoped;
use vm_device::BusDevice;
@@ -67,26 +67,26 @@ use vm_memory::ByteValued;
use vm_memory::{Bytes, GuestAddressSpace};
use vm_memory::{GuestAddress, GuestMemoryAtomic};
use vm_migration::{
snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot, SnapshotData, Snapshottable,
Transportable,
Migratable, MigratableError, Pausable, Snapshot, SnapshotData, Snapshottable, Transportable,
snapshot_from_id,
};
use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::signal::{register_signal_handler, SIGRTMIN};
use vmm_sys_util::signal::{SIGRTMIN, register_signal_handler};
use zerocopy::{FromBytes, Immutable, IntoBytes};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use crate::coredump::{
CpuElf64Writable, CpuSegment, CpuState as DumpCpusState, DumpState, Elf64Writable,
GuestDebuggableError, NoteDescType, X86_64ElfPrStatus, X86_64UserRegs, COREDUMP_NAME_SIZE,
NT_PRSTATUS,
COREDUMP_NAME_SIZE, CpuElf64Writable, CpuSegment, CpuState as DumpCpusState, DumpState,
Elf64Writable, GuestDebuggableError, NT_PRSTATUS, NoteDescType, X86_64ElfPrStatus,
X86_64UserRegs,
};
#[cfg(feature = "guest_debug")]
use crate::gdb::{get_raw_tid, Debuggable, DebuggableError};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::gdb::{Debuggable, DebuggableError, get_raw_tid};
use crate::seccomp_filters::{Thread, get_seccomp_filter};
#[cfg(target_arch = "x86_64")]
use crate::vm::physical_bits;
use crate::vm_config::CpusConfig;
use crate::{GuestMemoryMmap, CPU_MANAGER_SNAPSHOT_ID};
use crate::{CPU_MANAGER_SNAPSHOT_ID, GuestMemoryMmap};
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
/// Extract the specified bits of a 64-bit integer.
@@ -1835,7 +1835,7 @@ impl CpuManager {
_ => {
return Err(Error::TranslateVirtualAddress(anyhow!(format!(
"PA range not supported {pa_range}"
))))
))));
}
};
@@ -2858,8 +2858,8 @@ mod tests {
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};
use hypervisor::StandardRegisters;
use hypervisor::arch::x86::{FpuState, LapicState};
use linux_loader::loader::bootparam::setup_header;
#[test]
@@ -2912,7 +2912,7 @@ mod tests {
#[test]
fn test_setup_msrs() {
use hypervisor::arch::x86::{msr_index, MsrEntry};
use hypervisor::arch::x86::{MsrEntry, msr_index};
let hv = hypervisor::new().unwrap();
let vm = hv.create_vm().expect("new VM fd creation failed");
@@ -2997,6 +2997,7 @@ mod tests {
use std::{mem, mem::offset_of};
use arch::layout;
use hypervisor::HypervisorCpuError;
use hypervisor::arch::aarch64::regs::MPIDR_EL1;
#[cfg(feature = "kvm")]
use hypervisor::arm64_core_reg_id;
@@ -3004,9 +3005,8 @@ mod tests {
use hypervisor::kvm::aarch64::is_system_register;
#[cfg(feature = "kvm")]
use hypervisor::kvm::kvm_bindings::{
user_pt_regs, KVM_REG_ARM64, KVM_REG_ARM64_SYSREG, KVM_REG_ARM_CORE, KVM_REG_SIZE_U64,
KVM_REG_ARM_CORE, KVM_REG_ARM64, KVM_REG_ARM64_SYSREG, KVM_REG_SIZE_U64, user_pt_regs,
};
use hypervisor::HypervisorCpuError;
#[test]
fn test_setup_regs() {

View File

@@ -11,7 +11,7 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fs::{File, OpenOptions};
use std::io::{self, stdout, IsTerminal, Seek, SeekFrom};
use std::io::{self, IsTerminal, Seek, SeekFrom, stdout};
use std::num::Wrapping;
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, FromRawFd};
@@ -23,14 +23,14 @@ use std::time::Instant;
use acpi_tables::sdt::GenericAddress;
#[cfg(not(target_arch = "riscv64"))]
use acpi_tables::{aml, Aml};
use acpi_tables::{Aml, aml};
#[cfg(not(target_arch = "riscv64"))]
use anyhow::anyhow;
#[cfg(target_arch = "x86_64")]
use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START};
use arch::{layout, NumaNodes};
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
use arch::{DeviceType, MmioDeviceInfo};
use arch::{NumaNodes, layout};
use block::async_io::DiskFile;
use block::fixed_vhd_sync::FixedVhdDiskSync;
use block::qcow_sync::QcowDiskSync;
@@ -38,7 +38,7 @@ use block::raw_async_aio::RawFileDiskAio;
use block::raw_sync::RawFileDiskSync;
use block::vhdx_sync::VhdxDiskSync;
use block::{
block_aio_is_supported, block_io_uring_is_supported, detect_image_type, qcow, vhdx, ImageType,
ImageType, block_aio_is_supported, block_io_uring_is_supported, detect_image_type, qcow, vhdx,
};
#[cfg(feature = "io_uring")]
use block::{fixed_vhd_async::FixedVhdDiskAsync, raw_async::RawFileDisk};
@@ -55,26 +55,26 @@ use devices::interrupt_controller::InterruptController;
use devices::ioapic;
#[cfg(feature = "ivshmem")]
use devices::ivshmem::{IvshmemError, IvshmemOps};
#[cfg(all(feature = "fw_cfg", target_arch = "x86_64"))]
use devices::legacy::fw_cfg::FW_CFG_ACPI_ID;
#[cfg(target_arch = "aarch64")]
use devices::legacy::Pl011;
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
use devices::legacy::Serial;
#[cfg(all(feature = "fw_cfg", target_arch = "x86_64"))]
use devices::legacy::fw_cfg::FW_CFG_ACPI_ID;
#[cfg(feature = "fw_cfg")]
use devices::legacy::{
fw_cfg::{PORT_FW_CFG_BASE, PORT_FW_CFG_WIDTH},
FwCfg,
fw_cfg::{PORT_FW_CFG_BASE, PORT_FW_CFG_WIDTH},
};
#[cfg(feature = "pvmemcontrol")]
use devices::pvmemcontrol::{PvmemcontrolBusDevice, PvmemcontrolPciDevice};
use devices::{interrupt_controller, AcpiNotificationFlags};
use devices::{AcpiNotificationFlags, interrupt_controller};
use hypervisor::IoEventAddress;
#[cfg(target_arch = "aarch64")]
use hypervisor::arch::aarch64::regs::AARCH64_PMU_IRQ;
use hypervisor::IoEventAddress;
use libc::{
tcsetattr, termios, MAP_NORESERVE, MAP_PRIVATE, MAP_SHARED, O_TMPFILE, PROT_READ, PROT_WRITE,
TCSANOW,
MAP_NORESERVE, MAP_PRIVATE, MAP_SHARED, O_TMPFILE, PROT_READ, PROT_WRITE, TCSANOW, tcsetattr,
termios,
};
use pci::{
DeviceRelocation, MmioRegion, PciBarRegionType, PciBdf, PciDevice, VfioDmaMapping,
@@ -104,27 +104,27 @@ use vm_memory::{Address, GuestAddress, GuestMemoryRegion, GuestUsize, MmapRegion
use vm_memory::{GuestAddressSpace, GuestMemory};
use vm_migration::protocol::MemoryRangeTable;
use vm_migration::{
snapshot_from_id, state_from_id, Migratable, MigratableError, Pausable, Snapshot, SnapshotData,
Snapshottable, Transportable,
Migratable, MigratableError, Pausable, Snapshot, SnapshotData, Snapshottable, Transportable,
snapshot_from_id, state_from_id,
};
use vm_virtio::{AccessPlatform, VirtioDeviceType};
use vmm_sys_util::eventfd::EventFd;
use crate::console_devices::{ConsoleDeviceError, ConsoleInfo, ConsoleOutput};
use crate::cpu::{CpuManager, CPU_MANAGER_ACPI_SIZE};
use crate::cpu::{CPU_MANAGER_ACPI_SIZE, CpuManager};
use crate::device_tree::{DeviceNode, DeviceTree};
use crate::interrupt::{LegacyUserspaceInterruptManager, MsiInterruptManager};
use crate::memory_manager::{Error as MemoryManagerError, MemoryManager, MEMORY_MANAGER_ACPI_SIZE};
use crate::memory_manager::{Error as MemoryManagerError, MEMORY_MANAGER_ACPI_SIZE, MemoryManager};
use crate::pci_segment::PciSegment;
use crate::serial_manager::{Error as SerialManagerError, SerialManager};
#[cfg(feature = "ivshmem")]
use crate::vm_config::IvshmemConfig;
use crate::vm_config::{
ConsoleOutputMode, DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig,
VdpaConfig, VhostMode, VmConfig, VsockConfig, DEFAULT_IOMMU_ADDRESS_WIDTH_BITS,
DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT,
ConsoleOutputMode, DEFAULT_IOMMU_ADDRESS_WIDTH_BITS, DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT,
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig, VdpaConfig,
VhostMode, VmConfig, VsockConfig,
};
use crate::{device_node, GuestRegionMmap, PciDeviceInfo, DEVICE_MANAGER_SNAPSHOT_ID};
use crate::{DEVICE_MANAGER_SNAPSHOT_ID, GuestRegionMmap, PciDeviceInfo, device_node};
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
const MMIO_LEN: u64 = 0x1000;

View File

@@ -11,24 +11,24 @@ use std::sync::mpsc;
use gdbstub::arch::Arch;
use gdbstub::common::{Signal, Tid};
use gdbstub::conn::{Connection, ConnectionExt};
use gdbstub::stub::{run_blocking, DisconnectReason, MultiThreadStopReason};
use gdbstub::stub::{DisconnectReason, MultiThreadStopReason, run_blocking};
use gdbstub::target::ext::base::BaseOps;
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")]
use gdbstub_arch::aarch64::AArch64 as GdbArch;
#[cfg(target_arch = "x86_64")]
use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
#[cfg(target_arch = "aarch64")]
use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs;
#[cfg(target_arch = "x86_64")]
use gdbstub_arch::x86::X86_64_SSE as GdbArch;
#[cfg(target_arch = "x86_64")]
use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
use thiserror::Error;
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryError};

View File

@@ -10,21 +10,21 @@ use std::sync::{Arc, Mutex};
use igvm::snp_defs::SevVmsa;
use igvm::{IgvmDirectiveHeader, IgvmFile, IgvmPlatformHeader, IsolationType};
use igvm_defs::{
IgvmPageDataType, IgvmPlatformType, IGVM_VHS_PARAMETER, IGVM_VHS_PARAMETER_INSERT,
};
#[cfg(feature = "sev_snp")]
use igvm_defs::{MemoryMapEntryType, IGVM_VHS_MEMORY_MAP_ENTRY};
use igvm_defs::{IGVM_VHS_MEMORY_MAP_ENTRY, MemoryMapEntryType};
use igvm_defs::{
IGVM_VHS_PARAMETER, IGVM_VHS_PARAMETER_INSERT, IgvmPageDataType, IgvmPlatformType,
};
use mshv_bindings::*;
use thiserror::Error;
use zerocopy::IntoBytes;
use crate::cpu::CpuManager;
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;
use crate::cpu::CpuManager;
use crate::igvm::loader::Loader;
use crate::igvm::{BootPageAcceptance, HV_PAGE_SIZE, IgvmLoadedInfo, StartupMemoryType};
use crate::memory_manager::MemoryManager;
#[derive(Debug, Error)]
pub enum Error {

View File

@@ -10,7 +10,7 @@ use vm_memory::{
GuestMemoryRegion,
};
use crate::igvm::{BootPageAcceptance, StartupMemoryType, HV_PAGE_SIZE};
use crate::igvm::{BootPageAcceptance, HV_PAGE_SIZE, StartupMemoryType};
/// Structure to hold the guest memory info/layout to check
/// the if the memory is accepted within the layout.

View File

@@ -9,8 +9,8 @@ use std::path::Path;
#[cfg(test)]
use landlock::make_bitflags;
use landlock::{
path_beneath_rules, Access, AccessFs, BitFlags, Compatible, Ruleset, RulesetAttr,
RulesetCreated, RulesetCreatedAttr, RulesetError, ABI,
ABI, Access, AccessFs, BitFlags, Compatible, Ruleset, RulesetAttr, RulesetCreated,
RulesetCreatedAttr, RulesetError, path_beneath_rules,
};
use thiserror::Error;
@@ -59,7 +59,7 @@ impl TryFrom<&str> for LandlockAccess {
_ => {
return Err(LandlockError::InvalidLandlockAccess(
format!("Invalid access: {c}").to_string(),
))
));
}
};
}

View File

@@ -10,7 +10,7 @@ extern crate log;
use std::collections::HashMap;
use std::fs::File;
use std::io::{stdout, Read, Write};
use std::io::{Read, Write, stdout};
use std::net::{TcpListener, TcpStream};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::os::unix::net::{UnixListener, UnixStream};
@@ -29,12 +29,12 @@ use api::dbus::{DBusApiOptions, DBusApiShutdownChannels};
use api::http::HttpApiHandle;
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
use arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY;
use console_devices::{pre_create_console_devices, ConsoleInfo};
use console_devices::{ConsoleInfo, pre_create_console_devices};
use landlock::LandlockError;
use libc::{tcsetattr, termios, EFD_NONBLOCK, SIGINT, SIGTERM, TCSANOW};
use libc::{EFD_NONBLOCK, SIGINT, SIGTERM, TCSANOW, tcsetattr, termios};
use memory_manager::MemoryManagerSnapshotData;
use pci::PciBdf;
use seccompiler::{apply_filter, SeccompAction};
use seccompiler::{SeccompAction, apply_filter};
use serde::ser::{SerializeStruct, Serializer};
use serde::{Deserialize, Serialize};
use signal_hook::iterator::{Handle, Signals};
@@ -52,7 +52,7 @@ use crate::api::{
ApiRequest, ApiResponse, RequestHandler, VmInfoResponse, VmReceiveMigrationData,
VmSendMigrationData, VmmPingResponse,
};
use crate::config::{add_to_config, RestoreConfig};
use crate::config::{RestoreConfig, add_to_config};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use crate::coredump::GuestDebuggable;
use crate::landlock::Landlock;
@@ -60,7 +60,7 @@ use crate::memory_manager::MemoryManager;
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
use crate::migration::get_vm_snapshot;
use crate::migration::{recv_vm_config, recv_vm_state};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::seccomp_filters::{Thread, get_seccomp_filter};
use crate::vm::{Error as VmError, Vm, VmState};
use crate::vm_config::{
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig, VdpaConfig,
@@ -2469,14 +2469,15 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.devices
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.devices
.is_none()
);
assert!(vmm.vm_add_device(device_config.clone()).unwrap().is_none());
assert_eq!(
@@ -2516,19 +2517,21 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.user_devices
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.user_devices
.is_none()
);
assert!(vmm
.vm_add_user_device(user_device_config.clone())
.unwrap()
.is_none());
assert!(
vmm.vm_add_user_device(user_device_config.clone())
.unwrap()
.is_none()
);
assert_eq!(
vmm.vm_config
.as_ref()
@@ -2565,14 +2568,15 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.disks
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.disks
.is_none()
);
assert!(vmm.vm_add_disk(disk_config.clone()).unwrap().is_none());
assert_eq!(
@@ -2650,14 +2654,15 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.pmem
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.pmem
.is_none()
);
assert!(vmm.vm_add_pmem(pmem_config.clone()).unwrap().is_none());
assert_eq!(
@@ -2699,14 +2704,15 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.net
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.net
.is_none()
);
assert!(vmm.vm_add_net(net_config.clone()).unwrap().is_none());
assert_eq!(
@@ -2745,14 +2751,15 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.vdpa
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.vdpa
.is_none()
);
assert!(vmm.vm_add_vdpa(vdpa_config.clone()).unwrap().is_none());
assert_eq!(
@@ -2791,14 +2798,15 @@ mod unit_tests {
));
let _ = vmm.vm_create(create_dummy_vm_config());
assert!(vmm
.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.vsock
.is_none());
assert!(
vmm.vm_config
.as_ref()
.unwrap()
.lock()
.unwrap()
.vsock
.is_none()
);
assert!(vmm.vm_add_vsock(vsock_config.clone()).unwrap().is_none());
assert_eq!(

View File

@@ -17,7 +17,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::{Arc, Barrier, Mutex};
use std::{ffi, result, thread};
use acpi_tables::{aml, Aml};
use acpi_tables::{Aml, aml};
use anyhow::anyhow;
use arch::RegionType;
#[cfg(target_arch = "x86_64")]
@@ -278,7 +278,9 @@ pub enum Error {
/// It's invalid to try applying a NUMA policy to a memory zone that is
/// memory mapped with MAP_SHARED.
#[error("Invalid to try applying a NUMA policy to a memory zone that is memory mapped with MAP_SHARED")]
#[error(
"Invalid to try applying a NUMA policy to a memory zone that is memory mapped with MAP_SHARED"
)]
InvalidSharedMemoryZoneWithHostNuma,
/// Failed applying NUMA memory policy.
@@ -2611,7 +2613,7 @@ impl Migratable for MemoryManager {
return Err(MigratableError::MigrateSend(anyhow!(
"Error finding 'guest memory region' with address {:x}",
r.gpa
)))
)));
}
};

View File

@@ -11,11 +11,11 @@
use std::sync::{Arc, Mutex};
use acpi_tables::{aml, Aml};
use acpi_tables::{Aml, aml};
use arch::layout;
use pci::{DeviceRelocation, PciBdf, PciBus, PciConfigMmio, PciRoot};
#[cfg(target_arch = "x86_64")]
use pci::{PciConfigIo, PCI_CONFIG_IO_PORT, PCI_CONFIG_IO_PORT_SIZE};
use pci::{PCI_CONFIG_IO_PORT, PCI_CONFIG_IO_PORT_SIZE, PciConfigIo};
use uuid::Uuid;
use vm_allocator::AddressAllocator;
use vm_device::BusDeviceSync;
@@ -105,7 +105,12 @@ impl PciSegment {
info!(
"Adding PCI segment: id={}, PCI MMIO config address: 0x{:x}, mem32 area [0x{:x}-0x{:x}, mem64 area [0x{:x}-0x{:x}",
segment.id, segment.mmio_config_address, segment.start_of_mem32_area, segment.end_of_mem32_area, segment.start_of_mem64_area, segment.end_of_mem64_area
segment.id,
segment.mmio_config_address,
segment.start_of_mem32_area,
segment.end_of_mem32_area,
segment.start_of_mem64_area,
segment.end_of_mem64_area
);
Ok(segment)
}

View File

@@ -3,10 +3,10 @@
use std::cell::RefCell;
use std::collections::BTreeSet;
use std::fs::{read_dir, File};
use std::fs::{File, read_dir};
use std::io::{self, ErrorKind, Read, Write};
use std::iter::once;
use std::mem::{size_of, MaybeUninit};
use std::mem::{MaybeUninit, size_of};
use std::os::unix::prelude::*;
use std::process::exit;
use std::ptr::null_mut;
@@ -14,15 +14,16 @@ use std::ptr::null_mut;
use arch::_NSIG;
use hypervisor::HypervisorType;
use libc::{
c_int, c_void, close, fork, getpgrp, ioctl, pipe2, poll, pollfd, setsid, sigemptyset,
siginfo_t, signal, sigprocmask, syscall, tcgetpgrp, tcsetpgrp, SYS_close_range, EINVAL, ENOSYS,
ENOTTY, O_CLOEXEC, POLLERR, SIGCHLD, SIGWINCH, SIG_DFL, SIG_SETMASK, STDERR_FILENO, TIOCSCTTY,
EINVAL, ENOSYS, ENOTTY, O_CLOEXEC, POLLERR, SIG_DFL, SIG_SETMASK, SIGCHLD, SIGWINCH,
STDERR_FILENO, SYS_close_range, TIOCSCTTY, c_int, c_void, close, fork, getpgrp, ioctl, pipe2,
poll, pollfd, setsid, sigemptyset, siginfo_t, signal, sigprocmask, syscall, tcgetpgrp,
tcsetpgrp,
};
use seccompiler::{apply_filter, BpfProgram, SeccompAction};
use seccompiler::{BpfProgram, SeccompAction, apply_filter};
use vmm_sys_util::signal::register_signal_handler;
use crate::clone3::{clone3, clone_args, CLONE_CLEAR_SIGHAND};
use crate::seccomp_filters::{get_seccomp_filter, Thread};
use crate::clone3::{CLONE_CLEAR_SIGHAND, clone_args, clone3};
use crate::seccomp_filters::{Thread, get_seccomp_filter};
thread_local! {
// The tty file descriptor is stored in a global variable so it

View File

@@ -25,20 +25,20 @@ use std::time::Instant;
use std::{cmp, result, str, thread};
use anyhow::anyhow;
#[cfg(target_arch = "x86_64")]
use arch::layout::{KVM_IDENTITY_MAP_START, KVM_TSS_START};
#[cfg(feature = "tdx")]
use arch::x86_64::tdx::TdvfSection;
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
use arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY;
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
use arch::PciSpaceInfo;
use arch::{get_host_cpu_phys_bits, EntryPoint, NumaNode, NumaNodes};
#[cfg(target_arch = "x86_64")]
use arch::layout::{KVM_IDENTITY_MAP_START, KVM_TSS_START};
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
use arch::x86_64::MAX_SUPPORTED_CPUS_LEGACY;
#[cfg(feature = "tdx")]
use arch::x86_64::tdx::TdvfSection;
use arch::{EntryPoint, NumaNode, NumaNodes, get_host_cpu_phys_bits};
use devices::AcpiNotificationFlags;
#[cfg(target_arch = "aarch64")]
use devices::interrupt_controller;
#[cfg(feature = "fw_cfg")]
use devices::legacy::fw_cfg::FwCfgItem;
use devices::AcpiNotificationFlags;
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
@@ -46,17 +46,17 @@ use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
#[cfg(target_arch = "aarch64")]
use hypervisor::arch::aarch64::regs::AARCH64_PMU_IRQ;
use hypervisor::{HypervisorVmError, VmOps};
use libc::{termios, SIGWINCH};
use libc::{SIGWINCH, termios};
use linux_loader::cmdline::Cmdline;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use linux_loader::elf;
use linux_loader::loader::KernelLoader;
#[cfg(target_arch = "x86_64")]
use linux_loader::loader::bzimage::BzImage;
#[cfg(target_arch = "x86_64")]
use linux_loader::loader::elf::PvhBootCapability::PvhEntryPresent;
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
use linux_loader::loader::pe::Error::InvalidImageMagicNumber;
use linux_loader::loader::KernelLoader;
use seccompiler::SeccompAction;
use serde::{Deserialize, Serialize};
use thiserror::Error;
@@ -69,12 +69,12 @@ use vm_memory::{
};
use vm_migration::protocol::{MemoryRangeTable, Request, Response};
use vm_migration::{
snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable,
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, snapshot_from_id,
};
use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::sock_ctrl_msg::ScmSocket;
use crate::config::{add_to_config, ValidationError};
use crate::config::{ValidationError, add_to_config};
use crate::console_devices::{ConsoleDeviceError, ConsoleInfo};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use crate::coredump::{
@@ -94,7 +94,7 @@ use crate::memory_manager::{
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::migration::{SNAPSHOT_CONFIG_FILE, SNAPSHOT_STATE_FILE, url_to_path};
#[cfg(feature = "fw_cfg")]
use crate::vm_config::FwCfgConfig;
use crate::vm_config::{
@@ -102,8 +102,8 @@ use crate::vm_config::{
PmemConfig, UserDeviceConfig, VdpaConfig, VmConfig, VsockConfig,
};
use crate::{
cpu, GuestMemoryMmap, PciDeviceInfo, CPU_MANAGER_SNAPSHOT_ID, DEVICE_MANAGER_SNAPSHOT_ID,
MEMORY_MANAGER_SNAPSHOT_ID,
CPU_MANAGER_SNAPSHOT_ID, DEVICE_MANAGER_SNAPSHOT_ID, GuestMemoryMmap,
MEMORY_MANAGER_SNAPSHOT_ID, PciDeviceInfo, cpu,
};
/// Errors associated with VM management
@@ -1315,10 +1315,7 @@ impl Vm {
return Self::load_igvm(igvm, memory_manager, cpu_manager);
}
}
match (
&payload.firmware,
&payload.kernel,
) {
match (&payload.firmware, &payload.kernel) {
(Some(firmware), None) => {
let firmware = File::open(firmware).map_err(Error::FirmwareFile)?;
Self::load_kernel(firmware, None, memory_manager)
@@ -1328,7 +1325,9 @@ impl Vm {
let cmdline = Self::generate_cmdline(payload)?;
Self::load_kernel(kernel, Some(cmdline), memory_manager)
}
_ => unreachable!("Unsupported boot configuration: programming error from 'PayloadConfigError::validate()'"),
_ => unreachable!(
"Unsupported boot configuration: programming error from 'PayloadConfigError::validate()'"
),
}
}
@@ -1346,7 +1345,9 @@ impl Vm {
let kernel = File::open(kernel).map_err(Error::KernelFile)?;
Self::load_kernel(kernel, memory_manager)
}
_ => unreachable!("Unsupported boot configuration: programming error from 'PayloadConfigError::validate()'"),
_ => unreachable!(
"Unsupported boot configuration: programming error from 'PayloadConfigError::validate()'"
),
}
}

View File

@@ -13,8 +13,8 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use virtio_devices::RateLimiterConfig;
use crate::landlock::LandlockError;
use crate::Landlock;
use crate::landlock::LandlockError;
pub type LandlockResult<T> = result::Result<T, LandlockError>;
@@ -353,12 +353,16 @@ pub fn default_netconfig_tap() -> Option<String> {
}
pub fn default_netconfig_ip() -> IpAddr {
warn!("Deprecation warning: No IP address provided. A default IP address is assigned. This behavior will be deprecated soon.");
warn!(
"Deprecation warning: No IP address provided. A default IP address is assigned. This behavior will be deprecated soon."
);
IpAddr::V4(Ipv4Addr::new(192, 168, 249, 1))
}
pub fn default_netconfig_mask() -> IpAddr {
warn!("Deprecation warning: No network mask provided. A default network mask is assigned. This behavior will be deprecated soon.");
warn!(
"Deprecation warning: No network mask provided. A default network mask is assigned. This behavior will be deprecated soon."
);
IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0))
}
@@ -383,7 +387,9 @@ where
S: serde::Serializer,
{
if let Some(x) = x {
warn!("'NetConfig' contains FDs that can't be serialized correctly. Serializing them as invalid FDs.");
warn!(
"'NetConfig' contains FDs that can't be serialized correctly. Serializing them as invalid FDs."
);
let invalid_fds = vec![-1; x.len()];
s.serialize_some(&invalid_fds)
} else {
@@ -397,7 +403,9 @@ where
{
let invalid_fds: Option<Vec<i32>> = Option::deserialize(d)?;
if let Some(invalid_fds) = invalid_fds {
warn!("'NetConfig' contains FDs that can't be deserialized correctly. Deserializing them as invalid FDs.");
warn!(
"'NetConfig' contains FDs that can't be deserialized correctly. Deserializing them as invalid FDs."
);
Ok(Some(vec![-1; invalid_fds.len()]))
} else {
Ok(None)