@@ -30,8 +30,8 @@ use crate::vstate::vm::Vm;
30
30
pub enum VcpuArchError {
31
31
/// Failed to get register {0}: {1}
32
32
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 ) ,
35
35
/// Failed to retrieve list of registers: {0}
36
36
GetRegList ( kvm_ioctls:: Error ) ,
37
37
/// Failed to get multiprocessor state: {0}
@@ -178,7 +178,11 @@ impl KvmVcpu {
178
178
) -> Result < ( ) , KvmVcpuError > {
179
179
for reg in vcpu_config. cpu_config . regs . iter ( ) {
180
180
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
+ ) )
182
186
} ) ?;
183
187
}
184
188
@@ -322,7 +326,9 @@ impl KvmVcpu {
322
326
let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pstate) ;
323
327
self . fd
324
328
. 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
+ } ) ?;
326
332
327
333
// Other vCPUs are powered off initially awaiting PSCI wakeup.
328
334
if self . index == 0 {
@@ -331,17 +337,18 @@ impl KvmVcpu {
331
337
let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pc) ;
332
338
self . fd
333
339
. 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) ) ?;
335
341
336
342
// Last mandatory thing to set -> the address pointing to the FDT (also called DTB).
337
343
// "The device tree blob (dtb) must be placed on an 8-byte boundary and must
338
344
// not exceed 2 megabytes in size." -> https://www.kernel.org/doc/Documentation/arm64/booting.txt.
339
345
// We are choosing to place it the end of DRAM. See `get_fdt_addr`.
340
346
let regs0 = offset_of ! ( user_pt_regs, regs) + kreg_off;
341
347
let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , regs0) ;
348
+ let fdt_addr = get_fdt_addr ( mem) ;
342
349
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) ) ?;
345
352
346
353
// Reset the physical counter for the guest. This way we avoid guest reading
347
354
// host physical counter.
@@ -357,7 +364,9 @@ impl KvmVcpu {
357
364
if optional_capabilities. counter_offset {
358
365
self . fd
359
366
. 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
+ } ) ?;
361
370
}
362
371
}
363
372
Ok ( ( ) )
@@ -409,7 +418,7 @@ impl KvmVcpu {
409
418
pub fn set_register ( & self , reg : Aarch64RegisterRef ) -> Result < ( ) , VcpuArchError > {
410
419
self . fd
411
420
. 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) ) ?;
413
422
Ok ( ( ) )
414
423
}
415
424
@@ -569,6 +578,7 @@ mod tests {
569
578
err. unwrap_err( ) ,
570
579
KvmVcpuError :: ConfigureRegisters ( VcpuArchError :: SetOneReg (
571
580
0x6030000000100042 ,
581
+ "0x3c5" . to_string( ) ,
572
582
kvm_ioctls:: Error :: new( 9 )
573
583
) )
574
584
) ;
@@ -626,7 +636,7 @@ mod tests {
626
636
let res = vcpu. restore_state ( & faulty_vcpu_state) ;
627
637
assert ! ( matches!(
628
638
res. unwrap_err( ) ,
629
- KvmVcpuError :: RestoreState ( VcpuArchError :: SetOneReg ( 0 , _) )
639
+ KvmVcpuError :: RestoreState ( VcpuArchError :: SetOneReg ( 0 , _, _ ) )
630
640
) ) ;
631
641
632
642
vcpu. init ( & [ ] ) . unwrap ( ) ;
@@ -696,7 +706,7 @@ mod tests {
696
706
let res = vcpu. setup_boot_regs ( 0x0 , & mem, & optional_capabilities) ;
697
707
assert ! ( matches!(
698
708
res. unwrap_err( ) ,
699
- VcpuArchError :: SetOneReg ( 0x6030000000100042 , _)
709
+ VcpuArchError :: SetOneReg ( 0x6030000000100042 , _, _ )
700
710
) ) ;
701
711
702
712
vcpu. init_vcpu ( ) . unwrap ( ) ;
0 commit comments