1
1
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- use vmm:: arch:: aarch64:: regs:: RegSize ;
4
+ use vmm:: arch:: aarch64:: regs:: { RegSize , PC , SYS_CNTPCT_EL0 , SYS_CNTV_CVAL_EL0 } ;
5
5
use vmm:: cpu_config:: aarch64:: custom_cpu_template:: RegisterModifier ;
6
6
use vmm:: cpu_config:: templates:: { CpuConfiguration , CustomCpuTemplate , RegisterValueFilter } ;
7
7
use vmm:: logger:: warn;
@@ -26,6 +26,9 @@ pub fn config_to_template(cpu_config: &CpuConfiguration) -> CustomCpuTemplate {
26
26
}
27
27
} )
28
28
. collect ( ) ;
29
+
30
+ reg_modifiers. retain ( |modifier| !REG_EXCLUSION_LIST . contains ( & modifier. addr ) ) ;
31
+
29
32
reg_modifiers. sort_by_key ( |modifier| modifier. addr ) ;
30
33
31
34
CustomCpuTemplate {
@@ -34,9 +37,20 @@ pub fn config_to_template(cpu_config: &CpuConfiguration) -> CustomCpuTemplate {
34
37
}
35
38
}
36
39
40
+ // List of register IDs excluded from the CPU configuration dump.
41
+ const REG_EXCLUSION_LIST : [ u64 ; 3 ] = [
42
+ // SYS_CNTV_CVAL_EL0 and SYS_CNTPCT_EL0 are timer registers and depend on the elapsed time.
43
+ // This type of registers are not useful as guest CPU config dump.
44
+ SYS_CNTV_CVAL_EL0 ,
45
+ SYS_CNTPCT_EL0 ,
46
+ // Program counter (PC) value is determined by the given kernel image. It should not be
47
+ // overwritten by a custom CPU template and does not need to be tracked in a fingerprint file.
48
+ PC ,
49
+ ] ;
50
+
37
51
#[ cfg( test) ]
38
52
mod tests {
39
- use vmm:: arch:: aarch64:: regs:: { Aarch64RegisterRef , Aarch64RegisterVec } ;
53
+ use vmm:: arch:: aarch64:: regs:: { reg_size , Aarch64RegisterRef , Aarch64RegisterVec } ;
40
54
41
55
use super :: * ;
42
56
@@ -64,10 +78,16 @@ mod tests {
64
78
KVM_REG_SIZE_U64 ,
65
79
& 0x0000_ffff_0000_ffff_u64 . to_le_bytes ( ) ,
66
80
) ) ;
81
+ // CPU templates only supports 32, 64 and 128 bit wide registers, so the following registers
82
+ // should be excluded from the result.
67
83
v. push ( Aarch64RegisterRef :: new ( KVM_REG_SIZE_U256 , & [ 0x69 ; 32 ] ) ) ;
68
84
v. push ( Aarch64RegisterRef :: new ( KVM_REG_SIZE_U512 , & [ 0x69 ; 64 ] ) ) ;
69
85
v. push ( Aarch64RegisterRef :: new ( KVM_REG_SIZE_U1024 , & [ 0x69 ; 128 ] ) ) ;
70
86
v. push ( Aarch64RegisterRef :: new ( KVM_REG_SIZE_U2048 , & [ 0x69 ; 256 ] ) ) ;
87
+ // The following registers should be excluded from the result.
88
+ for id in REG_EXCLUSION_LIST {
89
+ v. push ( Aarch64RegisterRef :: new ( id, & vec ! [ 0 ; reg_size( id) ] ) ) ;
90
+ }
71
91
v
72
92
}
73
93
0 commit comments