@@ -36,18 +36,6 @@ pub struct Aarch64Register {
36
36
/// Errors thrown while setting aarch64 registers.
37
37
#[ derive( Debug , PartialEq , Eq , thiserror:: Error ) ]
38
38
pub enum Error {
39
- /// Failed to get core register (PC, PSTATE or general purpose ones).
40
- #[ error( "Failed to get {1} register: {0}" ) ]
41
- GetCoreRegister ( kvm_ioctls:: Error , String ) ,
42
- /// Failed to set core register (PC, PSTATE or general purpose ones).
43
- #[ error( "Failed to set {1} register: {0}" ) ]
44
- SetCoreRegister ( kvm_ioctls:: Error , String ) ,
45
- /// Failed to get a system register.
46
- #[ error( "Failed to get register: {0}: {1}" ) ]
47
- GetSysRegister ( u64 , kvm_ioctls:: Error ) ,
48
- /// Failed to set a system register.
49
- #[ error( "Failed to set register {0}: {1}" ) ]
50
- SetSysRegister ( u64 , kvm_ioctls:: Error ) ,
51
39
/// Failed to get a register value.
52
40
#[ error( "Failed to get register {0}: {1}" ) ]
53
41
GetOneReg ( u64 , kvm_ioctls:: Error ) ,
@@ -227,29 +215,26 @@ pub fn setup_boot_regs(
227
215
228
216
// Get the register index of the PSTATE (Processor State) register.
229
217
let pstate = offset__of ! ( user_pt_regs, pstate) + kreg_off;
230
- vcpu. set_one_reg (
231
- arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pstate) ,
232
- PSTATE_FAULT_BITS_64 . into ( ) ,
233
- )
234
- . map_err ( |err| Error :: SetCoreRegister ( err, "processor state" . to_string ( ) ) ) ?;
218
+ let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pstate) ;
219
+ vcpu. set_one_reg ( id, PSTATE_FAULT_BITS_64 . into ( ) )
220
+ . map_err ( |err| Error :: SetOneReg ( id, err) ) ?;
235
221
236
222
// Other vCPUs are powered off initially awaiting PSCI wakeup.
237
223
if cpu_id == 0 {
238
224
// Setting the PC (Processor Counter) to the current program address (kernel address).
239
225
let pc = offset__of ! ( user_pt_regs, pc) + kreg_off;
240
- vcpu. set_one_reg ( arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pc) , boot_ip. into ( ) )
241
- . map_err ( |err| Error :: SetCoreRegister ( err, "program counter" . to_string ( ) ) ) ?;
226
+ let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , pc) ;
227
+ vcpu. set_one_reg ( id, boot_ip. into ( ) )
228
+ . map_err ( |err| Error :: SetOneReg ( id, err) ) ?;
242
229
243
230
// Last mandatory thing to set -> the address pointing to the FDT (also called DTB).
244
231
// "The device tree blob (dtb) must be placed on an 8-byte boundary and must
245
232
// not exceed 2 megabytes in size." -> https://www.kernel.org/doc/Documentation/arm64/booting.txt.
246
233
// We are choosing to place it the end of DRAM. See `get_fdt_addr`.
247
234
let regs0 = offset__of ! ( user_pt_regs, regs) + kreg_off;
248
- vcpu. set_one_reg (
249
- arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , regs0) ,
250
- get_fdt_addr ( mem) . into ( ) ,
251
- )
252
- . map_err ( |err| Error :: SetCoreRegister ( err, "X0" . to_string ( ) ) ) ?;
235
+ let id = arm64_core_reg_id ! ( KVM_REG_SIZE_U64 , regs0) ;
236
+ vcpu. set_one_reg ( id, get_fdt_addr ( mem) . into ( ) )
237
+ . map_err ( |err| Error :: SetOneReg ( id, err) ) ?;
253
238
}
254
239
Ok ( ( ) )
255
240
}
@@ -261,7 +246,7 @@ pub fn setup_boot_regs(
261
246
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
262
247
pub fn read_mpidr ( vcpu : & VcpuFd ) -> Result < u64 > {
263
248
match vcpu. get_one_reg ( MPIDR_EL1 ) {
264
- Err ( err) => Err ( Error :: GetSysRegister ( MPIDR_EL1 , err) ) ,
249
+ Err ( err) => Err ( Error :: GetOneReg ( MPIDR_EL1 , err) ) ,
265
250
// MPIDR register is 64 bit wide on aarch64, this expect cannot fail
266
251
// on supported architectures
267
252
Ok ( val) => Ok ( val. try_into ( ) . expect ( "MPIDR register to be 64 bit" ) ) ,
@@ -371,7 +356,7 @@ pub fn save_registers(vcpu: &VcpuFd, ids: &[u64], state: &mut Vec<Aarch64Registe
371
356
id : * id,
372
357
value : vcpu
373
358
. get_one_reg ( * id)
374
- . map_err ( |e| Error :: GetSysRegister ( * id, e) ) ?,
359
+ . map_err ( |e| Error :: GetOneReg ( * id, e) ) ?,
375
360
} ) ;
376
361
}
377
362
@@ -387,7 +372,7 @@ pub fn save_registers(vcpu: &VcpuFd, ids: &[u64], state: &mut Vec<Aarch64Registe
387
372
pub fn restore_registers ( vcpu : & VcpuFd , state : & [ Aarch64Register ] ) -> Result < ( ) > {
388
373
for reg in state {
389
374
vcpu. set_one_reg ( reg. id , reg. value )
390
- . map_err ( |e| Error :: SetSysRegister ( reg. id , e) ) ?;
375
+ . map_err ( |e| Error :: SetOneReg ( reg. id , e) ) ?;
391
376
}
392
377
Ok ( ( ) )
393
378
}
@@ -431,7 +416,7 @@ mod tests {
431
416
let res = setup_boot_regs ( & vcpu, 0 , 0x0 , & mem) ;
432
417
assert_eq ! (
433
418
res. unwrap_err( ) ,
434
- Error :: SetCoreRegister ( kvm_ioctls:: Error :: new( 8 ) , "processor state" . to_string ( ) )
419
+ Error :: SetOneReg ( 6931039826524241986 , kvm_ioctls:: Error :: new( 8 ) )
435
420
) ;
436
421
437
422
let mut kvi: kvm_bindings:: kvm_vcpu_init = kvm_bindings:: kvm_vcpu_init:: default ( ) ;
@@ -452,7 +437,7 @@ mod tests {
452
437
let res = read_mpidr ( & vcpu) ;
453
438
assert_eq ! (
454
439
res. unwrap_err( ) ,
455
- Error :: GetSysRegister ( MPIDR_EL1 , kvm_ioctls:: Error :: new( 8 ) )
440
+ Error :: GetOneReg ( MPIDR_EL1 , kvm_ioctls:: Error :: new( 8 ) )
456
441
) ;
457
442
458
443
vcpu. vcpu_init ( & kvi) . unwrap ( ) ;
@@ -472,7 +457,7 @@ mod tests {
472
457
let res = save_core_registers ( & vcpu, & mut state) ;
473
458
assert_eq ! (
474
459
res. unwrap_err( ) ,
475
- Error :: GetCoreRegister ( kvm_ioctls:: Error :: new( 8 ) , "X0" . to_string ( ) )
460
+ Error :: GetOneReg ( 6931039826524241920 , kvm_ioctls:: Error :: new( 8 ) )
476
461
) ;
477
462
478
463
let res = save_all_registers ( & vcpu, & mut state) ;
0 commit comments