@@ -43,22 +43,24 @@ int32_t hcall_sos_offline_cpu(struct acrn_vm *vm, uint64_t lapicid)
43
43
{
44
44
struct acrn_vcpu * vcpu ;
45
45
uint16_t i ;
46
+ int32_t ret = 0 ;
46
47
47
48
pr_info ("sos offline cpu with lapicid %lld" , lapicid );
48
49
49
50
foreach_vcpu (i , vm , vcpu ) {
50
51
if (vlapic_get_apicid (vcpu_vlapic (vcpu )) == lapicid ) {
51
52
/* should not offline BSP */
52
53
if (vcpu -> vcpu_id == BOOT_CPU_ID ) {
53
- return -1 ;
54
+ ret = -1 ;
55
+ break ;
54
56
}
55
57
pause_vcpu (vcpu , VCPU_ZOMBIE );
56
58
reset_vcpu (vcpu );
57
59
offline_vcpu (vcpu );
58
60
}
59
61
}
60
62
61
- return 0 ;
63
+ return ret ;
62
64
}
63
65
64
66
/**
@@ -113,28 +115,28 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
113
115
struct vm_description vm_desc ;
114
116
115
117
(void )memset ((void * )& cv , 0U , sizeof (cv ));
116
- if (copy_from_gpa (vm , & cv , param , sizeof (cv )) != 0 ) {
117
- pr_err ("%s: Unable copy param to vm\n" , __func__ );
118
- return -1 ;
119
- }
120
-
121
- (void )memset (& vm_desc , 0U , sizeof (vm_desc ));
122
- vm_desc .sworld_supported = ((cv .vm_flag & (SECURE_WORLD_ENABLED )) != 0U );
123
- (void )memcpy_s (& vm_desc .GUID [0 ], 16U , & cv .GUID [0 ], 16U );
124
- ret = create_vm (& vm_desc , & target_vm );
118
+ if (copy_from_gpa (vm , & cv , param , sizeof (cv )) == 0 ) {
119
+ (void )memset (& vm_desc , 0U , sizeof (vm_desc ));
120
+ vm_desc .sworld_supported = ((cv .vm_flag & (SECURE_WORLD_ENABLED )) != 0U );
121
+ (void )memcpy_s (& vm_desc .GUID [0 ], 16U , & cv .GUID [0 ], 16U );
122
+
123
+ ret = create_vm (& vm_desc , & target_vm );
124
+ if (ret != 0 ) {
125
+ dev_dbg (ACRN_DBG_HYCALL , "HCALL: Create VM failed" );
126
+ cv .vmid = ACRN_INVALID_VMID ;
127
+ ret = -1 ;
128
+ } else {
129
+ cv .vmid = target_vm -> vm_id ;
130
+ ret = 0 ;
131
+ }
125
132
126
- if (ret != 0 ) {
127
- dev_dbg ( ACRN_DBG_HYCALL , "HCALL: Create VM failed" );
128
- cv . vmid = ACRN_INVALID_VMID ;
129
- ret = -1 ;
133
+ if (copy_to_gpa ( vm , & cv . vmid , param , sizeof ( cv . vmid )) != 0 ) {
134
+ pr_err ( "%s: Unable copy param to vm\n" , __func__ );
135
+ ret = -1 ;
136
+ }
130
137
} else {
131
- cv .vmid = target_vm -> vm_id ;
132
- ret = 0 ;
133
- }
134
-
135
- if (copy_to_gpa (vm , & cv .vmid , param , sizeof (cv .vmid )) != 0 ) {
136
138
pr_err ("%s: Unable copy param to vm\n" , __func__ );
137
- return -1 ;
139
+ ret = -1 ;
138
140
}
139
141
140
142
return ret ;
@@ -240,22 +242,20 @@ int32_t hcall_create_vcpu(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
240
242
struct acrn_vm * target_vm = get_vm_from_vmid (vmid );
241
243
242
244
if ((target_vm == NULL ) || (param == 0U )) {
243
- return -1 ;
244
- }
245
-
246
- if (copy_from_gpa (vm , & cv , param , sizeof (cv )) != 0 ) {
245
+ ret = -1 ;
246
+ } else if (copy_from_gpa (vm , & cv , param , sizeof (cv )) != 0 ) {
247
247
pr_err ("%s: Unable copy param to vm\n" , __func__ );
248
- return -1 ;
249
- }
250
-
251
- pcpu_id = allocate_pcpu ();
252
- if (pcpu_id == INVALID_CPU_ID ) {
253
- pr_err ("%s: No physical available\n" , __func__ );
254
- return -1 ;
248
+ ret = -1 ;
249
+ } else {
250
+ pcpu_id = allocate_pcpu ();
251
+ if (pcpu_id == INVALID_CPU_ID ) {
252
+ pr_err ("%s: No physical available\n" , __func__ );
253
+ ret = -1 ;
254
+ } else {
255
+ ret = prepare_vcpu (target_vm , pcpu_id );
256
+ }
255
257
}
256
258
257
- ret = prepare_vcpu (target_vm , pcpu_id );
258
-
259
259
return ret ;
260
260
}
261
261
@@ -303,30 +303,24 @@ int32_t hcall_set_vcpu_regs(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
303
303
struct acrn_vm * target_vm = get_vm_from_vmid (vmid );
304
304
struct acrn_set_vcpu_regs vcpu_regs ;
305
305
struct acrn_vcpu * vcpu ;
306
+ int32_t ret ;
306
307
307
- if ((target_vm == NULL ) || (param == 0U ) || is_vm0 (target_vm )) {
308
- return -1 ;
309
- }
310
-
311
- /* Only allow setup init ctx while target_vm is inactive */
312
- if (target_vm -> state == VM_STARTED ) {
313
- return -1 ;
314
- }
315
-
316
- if (copy_from_gpa (vm , & vcpu_regs , param , sizeof (vcpu_regs )) != 0 ) {
308
+ if ((target_vm == NULL ) || (param == 0U ) || is_vm0 (target_vm ) || (target_vm -> state == VM_STARTED )) {
309
+ /* Only allow setup init ctx while target_vm is inactive */
310
+ ret = -1 ;
311
+ } else if (copy_from_gpa (vm , & vcpu_regs , param , sizeof (vcpu_regs )) != 0 ) {
317
312
pr_err ("%s: Unable copy param to vm\n" , __func__ );
318
- return -1 ;
319
- }
320
-
321
- if (vcpu_regs .vcpu_id >= CONFIG_MAX_VCPUS_PER_VM ) {
313
+ ret = -1 ;
314
+ } else if (vcpu_regs .vcpu_id >= CONFIG_MAX_VCPUS_PER_VM ) {
322
315
pr_err ("%s: invalid vcpu_id for set_vcpu_regs\n" , __func__ );
323
- return -1 ;
316
+ ret = -1 ;
317
+ } else {
318
+ vcpu = vcpu_from_vid (target_vm , vcpu_regs .vcpu_id );
319
+ set_vcpu_regs (vcpu , & (vcpu_regs .vcpu_regs ));
320
+ ret = 0 ;
324
321
}
325
322
326
- vcpu = vcpu_from_vid (target_vm , vcpu_regs .vcpu_id );
327
- set_vcpu_regs (vcpu , & (vcpu_regs .vcpu_regs ));
328
-
329
- return 0 ;
323
+ return ret ;
330
324
}
331
325
332
326
/**
@@ -348,29 +342,29 @@ int32_t hcall_set_irqline(const struct acrn_vm *vm, uint16_t vmid,
348
342
{
349
343
uint32_t irq_pic ;
350
344
struct acrn_vm * target_vm = get_vm_from_vmid (vmid );
345
+ int32_t ret ;
351
346
352
347
if (target_vm == NULL ) {
353
- return - EINVAL ;
354
- }
355
-
356
- if (ops -> gsi >= vioapic_pincount (vm )) {
357
- return - EINVAL ;
358
- }
348
+ ret = - EINVAL ;
349
+ } else if (ops -> gsi >= vioapic_pincount (vm )) {
350
+ ret = - EINVAL ;
351
+ } else {
352
+ if (ops -> gsi < vpic_pincount ()) {
353
+ /*
354
+ * IRQ line for 8254 timer is connected to
355
+ * I/O APIC pin #2 but PIC pin #0,route GSI
356
+ * number #2 to PIC IRQ #0.
357
+ */
358
+ irq_pic = (ops -> gsi == 2U ) ? 0U : ops -> gsi ;
359
+ vpic_set_irq (target_vm , irq_pic , ops -> op );
360
+ }
359
361
360
- if (ops -> gsi < vpic_pincount ()) {
361
- /*
362
- * IRQ line for 8254 timer is connected to
363
- * I/O APIC pin #2 but PIC pin #0,route GSI
364
- * number #2 to PIC IRQ #0.
365
- */
366
- irq_pic = (ops -> gsi == 2U ) ? 0U : ops -> gsi ;
367
- vpic_set_irq (target_vm , irq_pic , ops -> op );
362
+ /* handle IOAPIC irqline */
363
+ vioapic_set_irq (target_vm , ops -> gsi , ops -> op );
364
+ ret = 0 ;
368
365
}
369
366
370
- /* handle IOAPIC irqline */
371
- vioapic_set_irq (target_vm , ops -> gsi , ops -> op );
372
-
373
- return 0 ;
367
+ return ret ;
374
368
}
375
369
376
370
/**
0 commit comments