@@ -14,7 +14,6 @@ use kvm_bindings::{
1414 kvm_mp_state, kvm_regs, kvm_sregs, kvm_vcpu_events, kvm_xcrs, kvm_xsave, kvm_xsave2,
1515} ;
1616use kvm_ioctls:: { VcpuExit , VcpuFd } ;
17- use log:: { error, warn} ;
1817use serde:: { Deserialize , Serialize } ;
1918use vmm_sys_util:: fam:: { self , FamStruct } ;
2019
@@ -24,7 +23,7 @@ use crate::arch::x86_64::interrupts;
2423use crate :: arch:: x86_64:: msr:: { MsrError , create_boot_msr_entries} ;
2524use crate :: arch:: x86_64:: regs:: { SetupFpuError , SetupRegistersError , SetupSpecialRegistersError } ;
2625use crate :: cpu_config:: x86_64:: { CpuConfiguration , cpuid} ;
27- use crate :: logger:: { IncMetric , METRICS } ;
26+ use crate :: logger:: { IncMetric , METRICS , error_rate_limited , warn_rate_limited } ;
2827use crate :: vstate:: bus:: Bus ;
2928use crate :: vstate:: memory:: GuestMemoryMmap ;
3029use crate :: vstate:: vcpu:: { VcpuConfig , VcpuEmulation , VcpuError } ;
@@ -281,7 +280,7 @@ impl KvmVcpu {
281280 // https://elixir.bootlin.com/linux/v6.17.5/source/arch/x86/kvm/x86.c#L5736-L5737
282281 if let Err ( err) = self . fd . kvmclock_ctrl ( ) {
283282 METRICS . vcpu . kvmclock_ctrl_fails . inc ( ) ;
284- warn ! ( "KVM_KVMCLOCK_CTRL call failed {}" , err) ;
283+ warn_rate_limited ! ( "KVM_KVMCLOCK_CTRL call failed {}" , err) ;
285284 }
286285 }
287286
@@ -403,7 +402,7 @@ impl KvmVcpu {
403402 . flat_map ( |msrs| msrs. as_mut_slice ( ) )
404403 . filter ( |msr| msr. index == MSR_IA32_TSC_DEADLINE && msr. data == 0 )
405404 . for_each ( |msr| {
406- warn ! (
405+ warn_rate_limited ! (
407406 "MSR_IA32_TSC_DEADLINE is 0, replacing with {:#x}." ,
408407 tsc_value
409408 ) ;
@@ -430,9 +429,10 @@ impl KvmVcpu {
430429 deferred_msrs
431430 . push ( * msr)
432431 . inspect_err ( |err| {
433- error ! (
432+ error_rate_limited ! (
434433 "Failed to move MSR {} into later chunk: {:?}" ,
435- msr. index, err
434+ msr. index,
435+ err
436436 )
437437 } )
438438 . is_err ( )
@@ -589,7 +589,9 @@ impl KvmVcpu {
589589 // v0.25 and newer snapshots without TSC will only work on
590590 // the same CPU model as the host on which they were taken.
591591 // TODO: Add negative test for this warning failure.
592- warn ! ( "TSC freq not available. Snapshot cannot be loaded on a different CPU model." ) ;
592+ warn_rate_limited ! (
593+ "TSC freq not available. Snapshot cannot be loaded on a different CPU model."
594+ ) ;
593595 None
594596 } ) ;
595597 let cpuid = self . get_cpuid ( ) ?;
@@ -729,7 +731,10 @@ impl Peripherals {
729731 if let Some ( pio_bus) = & self . pio_bus {
730732 let _metric = METRICS . vcpu . exit_io_in_agg . record_latency_metrics ( ) ;
731733 if let Err ( err) = pio_bus. read ( u64:: from ( addr) , data) {
732- warn ! ( "vcpu: IO read @ {addr:#x}:{:#x} failed: {err}" , data. len( ) ) ;
734+ warn_rate_limited ! (
735+ "vcpu: IO read @ {addr:#x}:{:#x} failed: {err}" ,
736+ data. len( )
737+ ) ;
733738 }
734739 METRICS . vcpu . exit_io_in . inc ( ) ;
735740 }
@@ -739,15 +744,18 @@ impl Peripherals {
739744 if let Some ( pio_bus) = & self . pio_bus {
740745 let _metric = METRICS . vcpu . exit_io_out_agg . record_latency_metrics ( ) ;
741746 if let Err ( err) = pio_bus. write ( u64:: from ( addr) , data) {
742- warn ! ( "vcpu: IO write @ {addr:#x}:{:#x} failed: {err}" , data. len( ) ) ;
747+ warn_rate_limited ! (
748+ "vcpu: IO write @ {addr:#x}:{:#x} failed: {err}" ,
749+ data. len( )
750+ ) ;
743751 }
744752 METRICS . vcpu . exit_io_out . inc ( ) ;
745753 }
746754 Ok ( VcpuEmulation :: Handled )
747755 }
748756 unexpected_exit => {
749757 METRICS . vcpu . failures . inc ( ) ;
750- error ! ( "Unexpected exit reason on vcpu run: {:?}" , unexpected_exit) ;
758+ error_rate_limited ! ( "Unexpected exit reason on vcpu run: {:?}" , unexpected_exit) ;
751759 Err ( VcpuError :: UnhandledKvmExit ( format ! (
752760 "{:?}" ,
753761 unexpected_exit
0 commit comments