diff --git a/src/vmm/src/arch/aarch64/cache_info.rs b/src/vmm/src/arch/aarch64/cache_info.rs index 2b4e2f5f82d..22f6a67c72e 100644 --- a/src/vmm/src/arch/aarch64/cache_info.rs +++ b/src/vmm/src/arch/aarch64/cache_info.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use std::{fs, io}; -use log::warn; +use crate::logger::warn; // Based on https://elixir.free-electrons.com/linux/v4.9.62/source/arch/arm64/kernel/cacheinfo.c#L29. const MAX_CACHE_LEVEL: u8 = 7; diff --git a/src/vmm/src/builder.rs b/src/vmm/src/builder.rs index 4229fc32656..730bd16d08a 100644 --- a/src/vmm/src/builder.rs +++ b/src/vmm/src/builder.rs @@ -17,7 +17,6 @@ use linux_loader::loader::elf::Elf as Loader; #[cfg(target_arch = "aarch64")] use linux_loader::loader::pe::PE as Loader; use linux_loader::loader::KernelLoader; -use log::error; use seccompiler::BpfThreadMap; use snapshot::Persist; use userfaultfd::Uffd; @@ -49,6 +48,7 @@ use crate::devices::virtio::{ use crate::devices::BusDevice; #[cfg(target_arch = "aarch64")] use crate::logger; +use crate::logger::error; use crate::persist::{MicrovmState, MicrovmStateError}; use crate::resources::VmResources; use crate::vmm_config::boot_source::BootConfig; diff --git a/src/vmm/src/cpu_config/x86_64/cpuid/amd/normalize.rs b/src/vmm/src/cpu_config/x86_64/cpuid/amd/normalize.rs index 65f1c682bc8..3c847bab2f5 100644 --- a/src/vmm/src/cpu_config/x86_64/cpuid/amd/normalize.rs +++ b/src/vmm/src/cpu_config/x86_64/cpuid/amd/normalize.rs @@ -83,7 +83,7 @@ pub enum ExtendedApicIdError { #[allow(clippy::multiple_inherent_impl)] impl super::AmdCpuid { /// We always use this brand string. - const DEFAULT_BRAND_STRING: &[u8; BRAND_STRING_LENGTH] = + const DEFAULT_BRAND_STRING: &'static [u8; BRAND_STRING_LENGTH] = b"AMD EPYC\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; /// Applies required modifications to CPUID respective of a vCPU. diff --git a/src/vmm/src/cpu_config/x86_64/custom_cpu_template.rs b/src/vmm/src/cpu_config/x86_64/custom_cpu_template.rs index 97c876b61eb..06bdf71ad9f 100644 --- a/src/vmm/src/cpu_config/x86_64/custom_cpu_template.rs +++ b/src/vmm/src/cpu_config/x86_64/custom_cpu_template.rs @@ -16,6 +16,7 @@ use crate::cpu_config::templates_serde::*; use crate::cpu_config::x86_64::cpuid::common::get_vendor_id_from_host; use crate::cpu_config::x86_64::cpuid::{KvmCpuidFlags, VENDOR_ID_AMD, VENDOR_ID_INTEL}; use crate::cpu_config::x86_64::static_cpu_templates::{c3, t2, t2a, t2cl, t2s, StaticCpuTemplate}; +use crate::logger::warn; impl GetCpuTemplate for Option { fn get_cpu_template(&self) -> Result, GetCpuTemplateError> { @@ -32,7 +33,7 @@ impl GetCpuTemplate for Option { return Err(CpuVendorMismatched); } if !CpuModel::get_cpu_model().is_at_least_cascade_lake() { - log::warn!( + warn!( "On processors that do not enumerate FBSDP_NO, PSDP_NO and \ SBDR_SSDP_NO on IA32_ARCH_CAPABILITIES MSR, the guest kernel \ does not apply the mitigation against MMIO stale data \ diff --git a/src/vmm/src/device_manager/mmio.rs b/src/vmm/src/device_manager/mmio.rs index b43535d2048..127b44a5915 100644 --- a/src/vmm/src/device_manager/mmio.rs +++ b/src/vmm/src/device_manager/mmio.rs @@ -11,7 +11,6 @@ use std::sync::{Arc, Mutex}; use kvm_ioctls::{IoEventAddress, VmFd}; use linux_loader::cmdline as kernel_cmdline; -use log::info; #[cfg(target_arch = "x86_64")] use utils::vm_memory::GuestAddress; use versionize::{VersionMap, Versionize, VersionizeResult}; @@ -30,6 +29,7 @@ use crate::devices::virtio::{ TYPE_RNG, TYPE_VSOCK, }; use crate::devices::BusDevice; +use crate::logger::info; /// Errors for MMIO device manager. #[derive(Debug, thiserror::Error, displaydoc::Display)] diff --git a/src/vmm/src/devices/legacy/i8042.rs b/src/vmm/src/devices/legacy/i8042.rs index a469a324a6d..2c3ce5c6c29 100644 --- a/src/vmm/src/devices/legacy/i8042.rs +++ b/src/vmm/src/devices/legacy/i8042.rs @@ -11,7 +11,7 @@ use std::num::Wrapping; use log::warn; use utils::eventfd::EventFd; -use crate::logger::{IncMetric, METRICS}; +use crate::logger::{error, IncMetric, METRICS}; /// Errors thrown by the i8042 device. #[derive(Debug, thiserror::Error, displaydoc::Display)] @@ -226,7 +226,7 @@ impl I8042Device { // our exit event fd. Meaning Firecracker will be exiting as soon as the VMM // thread wakes up to handle this event. if let Err(err) = self.reset_evt.write(1) { - log::error!("Failed to trigger i8042 reset event: {:?}", err); + error!("Failed to trigger i8042 reset event: {:?}", err); METRICS.i8042.error_count.inc(); } METRICS.i8042.reset_count.inc(); diff --git a/src/vmm/src/devices/pseudo/boot_timer.rs b/src/vmm/src/devices/pseudo/boot_timer.rs index 2551483ea53..ba16e92355f 100644 --- a/src/vmm/src/devices/pseudo/boot_timer.rs +++ b/src/vmm/src/devices/pseudo/boot_timer.rs @@ -3,6 +3,8 @@ use utils::time::TimestampUs; +use crate::logger::info; + const MAGIC_VALUE_SIGNAL_GUEST_BOOT_COMPLETE: u8 = 123; /// Pseudo device to record the kernel boot time. @@ -23,7 +25,7 @@ impl BootTimer { let boot_time_us = now_tm_us.time_us - self.start_ts.time_us; let boot_time_cpu_us = now_tm_us.cputime_us - self.start_ts.cputime_us; - log::info!( + info!( "Guest-boot-time = {:>6} us {} ms, {:>6} CPU us {} CPU ms", boot_time_us, boot_time_us / 1000, diff --git a/src/vmm/src/devices/virtio/balloon/event_handler.rs b/src/vmm/src/devices/virtio/balloon/event_handler.rs index 869cf0eb657..369e97f9430 100644 --- a/src/vmm/src/devices/virtio/balloon/event_handler.rs +++ b/src/vmm/src/devices/virtio/balloon/event_handler.rs @@ -4,12 +4,12 @@ use std::os::unix::io::AsRawFd; use event_manager::{EventOps, Events, MutEventSubscriber}; -use log::{error, warn}; use utils::epoll::EventSet; use crate::devices::report_balloon_event_fail; use crate::devices::virtio::balloon::device::Balloon; use crate::devices::virtio::{VirtioDevice, DEFLATE_INDEX, INFLATE_INDEX, STATS_INDEX}; +use crate::logger::{debug, error, warn}; impl Balloon { fn register_runtime_events(&self, ops: &mut EventOps) { @@ -36,7 +36,7 @@ impl Balloon { } fn process_activate_event(&self, ops: &mut EventOps) { - log::debug!("balloon: activate event"); + debug!("balloon: activate event"); if let Err(err) = self.activate_evt.read() { error!("Failed to consume balloon activate event: {:?}", err); } diff --git a/src/vmm/src/devices/virtio/balloon/util.rs b/src/vmm/src/devices/virtio/balloon/util.rs index 490c9960af8..baacb3834e7 100644 --- a/src/vmm/src/devices/virtio/balloon/util.rs +++ b/src/vmm/src/devices/virtio/balloon/util.rs @@ -6,6 +6,7 @@ use std::io; use utils::vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap, GuestMemoryRegion}; use super::{RemoveRegionError, MAX_PAGE_COMPACT_BUFFER}; +use crate::logger::error; /// This takes a vector of page frame numbers, and compacts them /// into ranges of consecutive pages. The result is a vector @@ -35,7 +36,7 @@ pub(crate) fn compact_page_frame_numbers(v: &mut [u32]) -> Vec<(u32, u32)> { // Skip duplicate pages. This will ensure we only consider // distinct PFNs. if page_frame_number == v[pfn_index - 1] { - log::error!("Skipping duplicate PFN {}.", page_frame_number); + error!("Skipping duplicate PFN {}.", page_frame_number); continue; } diff --git a/src/vmm/src/devices/virtio/block/event_handler.rs b/src/vmm/src/devices/virtio/block/event_handler.rs index a766471bf9f..e851de052d7 100644 --- a/src/vmm/src/devices/virtio/block/event_handler.rs +++ b/src/vmm/src/devices/virtio/block/event_handler.rs @@ -3,12 +3,12 @@ use std::os::unix::io::AsRawFd; use event_manager::{EventOps, Events, MutEventSubscriber}; -use log::{error, warn}; use utils::epoll::EventSet; use super::io::FileEngine; use crate::devices::virtio::block::device::Block; use crate::devices::virtio::VirtioDevice; +use crate::logger::{debug, error, warn}; impl Block { fn register_runtime_events(&self, ops: &mut EventOps) { @@ -32,7 +32,7 @@ impl Block { } fn process_activate_event(&self, ops: &mut EventOps) { - log::debug!("block: activate event"); + debug!("block: activate event"); if let Err(err) = self.activate_evt.read() { error!("Failed to consume block activate event: {:?}", err); } diff --git a/src/vmm/src/devices/virtio/device.rs b/src/vmm/src/devices/virtio/device.rs index 2b68df2530f..bc0a9b8a6ff 100644 --- a/src/vmm/src/devices/virtio/device.rs +++ b/src/vmm/src/devices/virtio/device.rs @@ -9,12 +9,12 @@ use std::fmt; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; -use log::warn; use utils::eventfd::EventFd; use utils::vm_memory::GuestMemoryMmap; use super::{ActivateError, Queue}; use crate::devices::virtio::{AsAny, VIRTIO_MMIO_INT_CONFIG, VIRTIO_MMIO_INT_VRING}; +use crate::logger::{error, warn}; /// Enum that indicates if a VirtioDevice is inactive or has been activated /// and memory attached to it. @@ -74,7 +74,7 @@ impl IrqTrigger { self.irq_status.fetch_or(irq as usize, Ordering::SeqCst); self.irq_evt.write(1).map_err(|err| { - log::error!("Failed to send irq to the guest: {:?}", err); + error!("Failed to send irq to the guest: {:?}", err); err })?; diff --git a/src/vmm/src/devices/virtio/mmio.rs b/src/vmm/src/devices/virtio/mmio.rs index a0cedbd71f3..e5a86e52c43 100644 --- a/src/vmm/src/devices/virtio/mmio.rs +++ b/src/vmm/src/devices/virtio/mmio.rs @@ -9,11 +9,11 @@ use std::fmt::Debug; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex, MutexGuard}; -use log::warn; use utils::byte_order; use utils::vm_memory::{GuestAddress, GuestMemoryMmap}; use super::{device_status, *}; +use crate::logger::warn; // TODO crosvm uses 0 here, but IIRC virtio specified some other vendor id that should be used const VENDOR_ID: u32 = 0; diff --git a/src/vmm/src/devices/virtio/net/event_handler.rs b/src/vmm/src/devices/virtio/net/event_handler.rs index da60aaa9a81..496a9b79dea 100644 --- a/src/vmm/src/devices/virtio/net/event_handler.rs +++ b/src/vmm/src/devices/virtio/net/event_handler.rs @@ -4,12 +4,11 @@ use std::os::unix::io::AsRawFd; use event_manager::{EventOps, Events, MutEventSubscriber}; -use log::{error, warn}; use utils::epoll::EventSet; use crate::devices::virtio::net::device::Net; use crate::devices::virtio::{VirtioDevice, RX_INDEX, TX_INDEX}; -use crate::logger::{IncMetric, METRICS}; +use crate::logger::{debug, error, warn, IncMetric, METRICS}; impl Net { fn register_runtime_events(&self, ops: &mut EventOps) { @@ -40,7 +39,7 @@ impl Net { } fn process_activate_event(&self, ops: &mut EventOps) { - log::debug!("net: activate event"); + debug!("net: activate event"); if let Err(err) = self.activate_evt.read() { error!("Failed to consume net activate event: {:?}", err); } diff --git a/src/vmm/src/devices/virtio/queue.rs b/src/vmm/src/devices/virtio/queue.rs index 2d9c1851d42..9ef75b6b9cb 100644 --- a/src/vmm/src/devices/virtio/queue.rs +++ b/src/vmm/src/devices/virtio/queue.rs @@ -9,11 +9,12 @@ use std::cmp::min; use std::num::Wrapping; use std::sync::atomic::{fence, Ordering}; -use log::error; use utils::vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap, }; +use crate::logger::error; + pub(super) const VIRTQ_DESC_F_NEXT: u16 = 0x1; pub(super) const VIRTQ_DESC_F_WRITE: u16 = 0x2; diff --git a/src/vmm/src/devices/virtio/rng/event_handler.rs b/src/vmm/src/devices/virtio/rng/event_handler.rs index 1186901c136..4d41e4b4e85 100644 --- a/src/vmm/src/devices/virtio/rng/event_handler.rs +++ b/src/vmm/src/devices/virtio/rng/event_handler.rs @@ -4,11 +4,11 @@ use std::os::unix::io::AsRawFd; use event_manager::{EventOps, Events, MutEventSubscriber}; -use log::{error, warn}; use utils::epoll::EventSet; use super::{Entropy, RNG_QUEUE}; use crate::devices::virtio::VirtioDevice; +use crate::logger::{error, warn}; impl Entropy { fn register_runtime_events(&self, ops: &mut EventOps) { diff --git a/src/vmm/src/logger/metrics.rs b/src/vmm/src/logger/metrics.rs index eb4bb8522ec..5f05871ab28 100644 --- a/src/vmm/src/logger/metrics.rs +++ b/src/vmm/src/logger/metrics.rs @@ -67,13 +67,13 @@ use std::ops::Deref; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Mutex, OnceLock}; -#[cfg(target_arch = "aarch64")] -use log::warn; use serde::{Serialize, Serializer}; #[cfg(target_arch = "aarch64")] use vm_superio::rtc_pl031::RtcEvents; use super::FcLineWriter; +#[cfg(target_arch = "aarch64")] +use crate::warn; /// Static instance used for handling metrics. pub static METRICS: Metrics = diff --git a/src/vmm/src/logger/mod.rs b/src/vmm/src/logger/mod.rs index 60c2d2a072c..83119a821e7 100644 --- a/src/vmm/src/logger/mod.rs +++ b/src/vmm/src/logger/mod.rs @@ -12,8 +12,7 @@ mod metrics; use std::sync::LockResult; -pub use log::Level::*; -pub use log::{warn, *}; +pub use log::{debug, error, info, log_enabled, trace, warn, Level, LevelFilter}; pub use crate::logger::logging::{LoggerError, LOGGER}; #[cfg(target_arch = "aarch64")] diff --git a/src/vmm/src/persist.rs b/src/vmm/src/persist.rs index 7907bb5d7e6..ed0dfdac63b 100644 --- a/src/vmm/src/persist.rs +++ b/src/vmm/src/persist.rs @@ -11,7 +11,6 @@ use std::os::unix::net::UnixStream; use std::path::Path; use std::sync::{Arc, Mutex}; -use log::{info, warn}; use seccompiler::BpfThreadMap; use semver::Version; use serde::Serialize; @@ -33,6 +32,7 @@ use crate::cpu_config::x86_64::cpuid::common::get_vendor_id_from_host; use crate::cpu_config::x86_64::cpuid::CpuidTrait; use crate::device_manager::persist::{DevicePersistError, DeviceStates}; use crate::devices::virtio::TYPE_NET; +use crate::logger::{info, warn}; use crate::memory_snapshot::{GuestMemoryState, SnapshotMemory}; use crate::resources::VmResources; #[cfg(target_arch = "x86_64")] diff --git a/src/vmm/src/resources.rs b/src/vmm/src/resources.rs index e4ed88a504c..f06bc6d8de4 100644 --- a/src/vmm/src/resources.rs +++ b/src/vmm/src/resources.rs @@ -10,6 +10,7 @@ use utils::net::ipv4addr::is_link_local_valid; use crate::cpu_config::templates::CustomCpuTemplate; use crate::device_manager::persist::SharedDeviceType; +use crate::logger::info; use crate::mmds; use crate::mmds::data_store::{Mmds, MmdsVersion}; use crate::mmds::ns::MmdsNetworkStack; @@ -172,7 +173,7 @@ impl VmResources { resources.locked_mmds_or_default().put_data( serde_json::from_str(data).expect("MMDS error: metadata provided not valid json"), )?; - log::info!("Successfully added metadata to mmds from file"); + info!("Successfully added metadata to mmds from file"); } if let Some(mmds_config) = vmm_config.mmds_config {