Skip to content

Commit 1b37ed5

Browse files
Shawnshhwenlingz
authored andcommitted
hv: vmcall: fix "goto detected" violations
Remove the goto by split the function into two, dispatch_hypercall and vmcall_vmexit_handler. Tracked-On: #861 Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent f6ae835 commit 1b37ed5

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,18 @@ static spinlock_t vmm_hypercall_lock = {
1111
.head = 0U,
1212
.tail = 0U,
1313
};
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)
2016
{
21-
int32_t ret = -EACCES;
2217
struct acrn_vm *vm = vcpu->vm;
2318
/* hypercall ID from guest*/
2419
uint64_t hypcall_id = vcpu_get_gpreg(vcpu, CPU_REG_R8);
2520
/* hypercall param1 from guest*/
2621
uint64_t param1 = vcpu_get_gpreg(vcpu, CPU_REG_RDI);
2722
/* hypercall param2 from guest*/
2823
uint64_t param2 = vcpu_get_gpreg(vcpu, CPU_REG_RSI);
24+
int32_t ret;
2925

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 */
4326
switch (hypcall_id) {
4427
case HC_SOS_OFFLINE_CPU:
4528
spinlock_obtain(&vmm_hypercall_lock);
@@ -194,7 +177,34 @@ int32_t vmcall_vmexit_handler(struct acrn_vcpu *vcpu)
194177
break;
195178
}
196179

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+
198208
vcpu_set_gpreg(vcpu, CPU_REG_RAX, (uint64_t)ret);
199209

200210
TRACE_2L(TRACE_VMEXIT_VMCALL, vm->vm_id, hypcall_id);

0 commit comments

Comments
 (0)