@@ -65,18 +65,18 @@ static struct proc_entry proc_entry_template = {
65
65
.feature_flags = MPEP_FEATURES
66
66
};
67
67
68
- static uint8_t mpt_compute_checksum (void * base , size_t len )
68
+ static uint8_t mpt_compute_checksum (const void * base , size_t len )
69
69
{
70
- uint8_t * bytes ;
71
- uint8_t sum ;
72
- size_t length = len ;
70
+ uint8_t sum = 0U ;
71
+ size_t length ;
72
+ const uint8_t * bytes = base ;
73
73
74
- for (bytes = base , sum = 0U ; length > 0U ; length -- ) {
74
+ for (length = len ; length > 0U ; length -- ) {
75
75
sum += * bytes ;
76
76
bytes ++ ;
77
77
}
78
78
79
- return (256U - sum );
79
+ return (~ sum ) + 1U ;
80
80
}
81
81
82
82
/**
@@ -92,6 +92,7 @@ int32_t mptable_build(struct acrn_vm *vm)
92
92
size_t mptable_length ;
93
93
uint16_t i ;
94
94
uint16_t vcpu_num ;
95
+ int32_t ret = 0 ;
95
96
uint64_t pcpu_bitmap = 0U ;
96
97
struct mptable_info * mptable ;
97
98
struct acrn_vm_config * vm_config ;
@@ -110,35 +111,36 @@ int32_t mptable_build(struct acrn_vm *vm)
110
111
+ MPEII_NUM_LOCAL_IRQ * sizeof (struct int_entry );
111
112
112
113
mptable_length = sizeof (struct mpfps ) + mptable -> mpch .base_table_length ;
113
- if (mptable_length > MPTABLE_MAX_LENGTH ) {
114
- return -1 ;
115
- }
116
-
117
- for (i = 0U ; i < vcpu_num ; i ++ ) {
118
- uint16_t pcpu_id = ffs64 (pcpu_bitmap );
119
-
120
- (void )memcpy_s ((void * )(mptable -> proc_entry_array + i ), sizeof (struct proc_entry ),
121
- (const void * )& proc_entry_template , sizeof (struct proc_entry ));
122
- mptable -> proc_entry_array [i ].apic_id = (uint8_t ) i ;
123
- if (i == 0U ) {
124
- mptable -> proc_entry_array [i ].cpu_flags |= PROCENTRY_FLAG_BP ;
114
+ if (mptable_length <= MPTABLE_MAX_LENGTH ) {
115
+ for (i = 0U ; i < vcpu_num ; i ++ ) {
116
+ uint16_t pcpu_id = ffs64 (pcpu_bitmap );
117
+
118
+ (void )memcpy_s ((void * )(mptable -> proc_entry_array + i ), sizeof (struct proc_entry ),
119
+ (const void * )& proc_entry_template , sizeof (struct proc_entry ));
120
+ mptable -> proc_entry_array [i ].apic_id = (uint8_t ) i ;
121
+ if (i == 0U ) {
122
+ mptable -> proc_entry_array [i ].cpu_flags |= PROCENTRY_FLAG_BP ;
123
+ }
124
+ bitmap_clear_lock (pcpu_id , & pcpu_bitmap );
125
125
}
126
- bitmap_clear_lock (pcpu_id , & pcpu_bitmap );
127
- }
128
126
129
- /* Copy mptable info into guest memory */
130
- (void )copy_to_gpa (vm , (void * )mptable , MPTABLE_BASE , mptable_length );
131
-
132
- startaddr = (char * )gpa2hva (vm , MPTABLE_BASE );
133
- curraddr = startaddr ;
134
- stac ();
135
- mpfp = (struct mpfps * )curraddr ;
136
- mpfp -> checksum = mpt_compute_checksum (mpfp , sizeof (struct mpfps ));
137
- curraddr += sizeof (struct mpfps );
138
-
139
- mpch = (struct mpcth * )curraddr ;
140
- mpch -> checksum = mpt_compute_checksum (mpch , mpch -> base_table_length );
141
- clac ();
127
+ /* Copy mptable info into guest memory */
128
+ (void )copy_to_gpa (vm , (void * )mptable , MPTABLE_BASE , mptable_length );
129
+
130
+ startaddr = (char * )gpa2hva (vm , MPTABLE_BASE );
131
+ curraddr = startaddr ;
132
+ stac ();
133
+ mpfp = (struct mpfps * )curraddr ;
134
+ mpfp -> checksum = mpt_compute_checksum (mpfp , sizeof (struct mpfps ));
135
+ curraddr += sizeof (struct mpfps );
136
+
137
+ mpch = (struct mpcth * )curraddr ;
138
+ mpch -> checksum = mpt_compute_checksum (mpch , mpch -> base_table_length );
139
+ clac ();
140
+ ret = 0 ;
141
+ } else {
142
+ ret = -1 ;
143
+ }
142
144
143
- return 0U ;
145
+ return ret ;
144
146
}
0 commit comments