@@ -11,35 +11,18 @@ static spinlock_t vmm_hypercall_lock = {
11
11
.head = 0U ,
12
12
.tail = 0U ,
13
13
};
14
- /*
15
- * Pass return value to SOS by register rax.
16
- * This function should always return 0 since we shouldn't
17
- * deal with hypercall error in hypervisor.
18
- */
19
- int32_t vmcall_vmexit_handler (struct acrn_vcpu * vcpu )
14
+
15
+ static int32_t dispatch_hypercall (struct acrn_vcpu * vcpu )
20
16
{
21
- int32_t ret = - EACCES ;
22
17
struct acrn_vm * vm = vcpu -> vm ;
23
18
/* hypercall ID from guest*/
24
19
uint64_t hypcall_id = vcpu_get_gpreg (vcpu , CPU_REG_R8 );
25
20
/* hypercall param1 from guest*/
26
21
uint64_t param1 = vcpu_get_gpreg (vcpu , CPU_REG_RDI );
27
22
/* hypercall param2 from guest*/
28
23
uint64_t param2 = vcpu_get_gpreg (vcpu , CPU_REG_RSI );
24
+ int32_t ret ;
29
25
30
- if (!is_hypercall_from_ring0 ()) {
31
- pr_err ("hypercall is only allowed from RING-0!\n" );
32
- goto out ;
33
- }
34
-
35
- if (!is_vm0 (vm ) && (hypcall_id != HC_WORLD_SWITCH ) &&
36
- (hypcall_id != HC_INITIALIZE_TRUSTY ) &&
37
- (hypcall_id != HC_SAVE_RESTORE_SWORLD_CTX )) {
38
- pr_err ("hypercall %d is only allowed from VM0!\n" , hypcall_id );
39
- goto out ;
40
- }
41
-
42
- /* Dispatch the hypercall handler */
43
26
switch (hypcall_id ) {
44
27
case HC_SOS_OFFLINE_CPU :
45
28
spinlock_obtain (& vmm_hypercall_lock );
@@ -194,7 +177,34 @@ int32_t vmcall_vmexit_handler(struct acrn_vcpu *vcpu)
194
177
break ;
195
178
}
196
179
197
- out :
180
+ return ret ;
181
+ }
182
+
183
+ /*
184
+ * Pass return value to SOS by register rax.
185
+ * This function should always return 0 since we shouldn't
186
+ * deal with hypercall error in hypervisor.
187
+ */
188
+ int32_t vmcall_vmexit_handler (struct acrn_vcpu * vcpu )
189
+ {
190
+ int32_t ret ;
191
+ struct acrn_vm * vm = vcpu -> vm ;
192
+ /* hypercall ID from guest*/
193
+ uint64_t hypcall_id = vcpu_get_gpreg (vcpu , CPU_REG_R8 );
194
+
195
+ if (!is_hypercall_from_ring0 ()) {
196
+ pr_err ("hypercall is only allowed from RING-0!\n" );
197
+ ret = - EACCES ;
198
+ } else if (!is_vm0 (vm ) && (hypcall_id != HC_WORLD_SWITCH ) &&
199
+ (hypcall_id != HC_INITIALIZE_TRUSTY ) &&
200
+ (hypcall_id != HC_SAVE_RESTORE_SWORLD_CTX )) {
201
+ pr_err ("hypercall %d is only allowed from VM0!\n" , hypcall_id );
202
+ ret = - EACCES ;
203
+ } else {
204
+ /* Dispatch the hypercall handler */
205
+ ret = dispatch_hypercall (vcpu );
206
+ }
207
+
198
208
vcpu_set_gpreg (vcpu , CPU_REG_RAX , (uint64_t )ret );
199
209
200
210
TRACE_2L (TRACE_VMEXIT_VMCALL , vm -> vm_id , hypcall_id );
0 commit comments