@@ -30,8 +30,8 @@ use crate::vstate::vm::Vm;
3030pub enum VcpuArchError {
3131 /// Failed to get register {0}: {1}
3232 GetOneReg ( u64 , kvm_ioctls:: Error ) ,
33- /// Failed to set register {0}: {1 }
34- SetOneReg ( u64 , kvm_ioctls:: Error ) ,
33+ /// Failed to set register {0:#x} to value {1}: {2 }
34+ SetOneReg ( u64 , String , kvm_ioctls:: Error ) ,
3535 /// Failed to retrieve list of registers: {0}
3636 GetRegList ( kvm_ioctls:: Error ) ,
3737 /// Failed to get multiprocessor state: {0}
@@ -178,7 +178,11 @@ impl KvmVcpu {
178178 ) -> Result < ( ) , KvmVcpuError > {
179179 for reg in vcpu_config. cpu_config . regs . iter ( ) {
180180 self . fd . set_one_reg ( reg. id , reg. as_slice ( ) ) . map_err ( |err| {
181- KvmVcpuError :: ApplyCpuTemplate ( VcpuArchError :: SetOneReg ( reg. id , err) )
181+ KvmVcpuError :: ApplyCpuTemplate ( VcpuArchError :: SetOneReg (
182+ reg. id ,
183+ reg. value_str ( ) ,
184+ err,
185+ ) )
182186 } ) ?;
183187 }
184188
@@ -322,7 +326,9 @@ impl KvmVcpu {
322326 let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pstate) ;
323327 self . fd
324328 . set_one_reg ( id, & PSTATE_FAULT_BITS_64 . to_le_bytes ( ) )
325- . map_err ( |err| VcpuArchError :: SetOneReg ( id, err) ) ?;
329+ . map_err ( |err| {
330+ VcpuArchError :: SetOneReg ( id, format ! ( "{PSTATE_FAULT_BITS_64:#x}" ) , err)
331+ } ) ?;
326332
327333 // Other vCPUs are powered off initially awaiting PSCI wakeup.
328334 if self . index == 0 {
@@ -331,17 +337,18 @@ impl KvmVcpu {
331337 let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pc) ;
332338 self . fd
333339 . set_one_reg ( id, & boot_ip. to_le_bytes ( ) )
334- . map_err ( |err| VcpuArchError :: SetOneReg ( id, err) ) ?;
340+ . map_err ( |err| VcpuArchError :: SetOneReg ( id, format ! ( "{boot_ip:#x}" ) , err) ) ?;
335341
336342 // Last mandatory thing to set -> the address pointing to the FDT (also called DTB).
337343 // "The device tree blob (dtb) must be placed on an 8-byte boundary and must
338344 // not exceed 2 megabytes in size." -> https://www.kernel.org/doc/Documentation/arm64/booting.txt.
339345 // We are choosing to place it the end of DRAM. See `get_fdt_addr`.
340346 let regs0 = offset_of ! ( user_pt_regs, regs) + kreg_off;
341347 let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , regs0) ;
348+ let fdt_addr = get_fdt_addr ( mem) ;
342349 self . fd
343- . set_one_reg ( id, & get_fdt_addr ( mem ) . to_le_bytes ( ) )
344- . map_err ( |err| VcpuArchError :: SetOneReg ( id, err) ) ?;
350+ . set_one_reg ( id, & fdt_addr . to_le_bytes ( ) )
351+ . map_err ( |err| VcpuArchError :: SetOneReg ( id, format ! ( "{fdt_addr:#x}" ) , err) ) ?;
345352
346353 // Reset the physical counter for the guest. This way we avoid guest reading
347354 // host physical counter.
@@ -357,7 +364,9 @@ impl KvmVcpu {
357364 if optional_capabilities. counter_offset {
358365 self . fd
359366 . set_one_reg ( KVM_REG_ARM_PTIMER_CNT , & [ 0 ; 8 ] )
360- . map_err ( |err| VcpuArchError :: SetOneReg ( id, err) ) ?;
367+ . map_err ( |err| {
368+ VcpuArchError :: SetOneReg ( id, format ! ( "{KVM_REG_ARM_PTIMER_CNT:#x}" ) , err)
369+ } ) ?;
361370 }
362371 }
363372 Ok ( ( ) )
@@ -409,7 +418,7 @@ impl KvmVcpu {
409418 pub fn set_register ( & self , reg : Aarch64RegisterRef ) -> Result < ( ) , VcpuArchError > {
410419 self . fd
411420 . set_one_reg ( reg. id , reg. as_slice ( ) )
412- . map_err ( |e| VcpuArchError :: SetOneReg ( reg. id , e) ) ?;
421+ . map_err ( |e| VcpuArchError :: SetOneReg ( reg. id , reg . value_str ( ) , e) ) ?;
413422 Ok ( ( ) )
414423 }
415424
@@ -569,6 +578,7 @@ mod tests {
569578 err. unwrap_err( ) ,
570579 KvmVcpuError :: ConfigureRegisters ( VcpuArchError :: SetOneReg (
571580 0x6030000000100042 ,
581+ String :: new( ) ,
572582 kvm_ioctls:: Error :: new( 9 )
573583 ) )
574584 ) ;
@@ -626,7 +636,7 @@ mod tests {
626636 let res = vcpu. restore_state ( & faulty_vcpu_state) ;
627637 assert ! ( matches!(
628638 res. unwrap_err( ) ,
629- KvmVcpuError :: RestoreState ( VcpuArchError :: SetOneReg ( 0 , _) )
639+ KvmVcpuError :: RestoreState ( VcpuArchError :: SetOneReg ( 0 , _, _ ) )
630640 ) ) ;
631641
632642 vcpu. init ( & [ ] ) . unwrap ( ) ;
@@ -696,7 +706,7 @@ mod tests {
696706 let res = vcpu. setup_boot_regs ( 0x0 , & mem, & optional_capabilities) ;
697707 assert ! ( matches!(
698708 res. unwrap_err( ) ,
699- VcpuArchError :: SetOneReg ( 0x6030000000100042 , _)
709+ VcpuArchError :: SetOneReg ( 0x6030000000100042 , _, _ )
700710 ) ) ;
701711
702712 vcpu. init_vcpu ( ) . unwrap ( ) ;
0 commit comments