Skip to content

Commit 10bde52

Browse files
Shawnshhwenlingz
authored andcommitted
hv: other: fix "Procedure has more than one exit point"
IEC 61508,ISO 26262 standards highly recommend single-exit rule. Reduce the count of the "return entries". Fix the violations which is comply with the cases list below: 1.Function has 2 return entries. 2.The first return entry is used to return the error code of checking variable whether is valid. Fix the violations in "if else" format. Tracked-On: #861 Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent fe3de67 commit 10bde52

File tree

4 files changed

+70
-71
lines changed

4 files changed

+70
-71
lines changed

hypervisor/arch/x86/notify.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,5 @@ void setup_posted_intr_notification(void)
111111
posted_intr_notification,
112112
NULL, IRQF_NONE) < 0) {
113113
pr_err("Failed to setup posted-intr notification");
114-
return;
115114
}
116115
}

hypervisor/arch/x86/pm.c

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -131,66 +131,66 @@ void enter_s3(struct acrn_vm *vm, uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val)
131131

132132
/* We assume enter s3 success by default */
133133
host_enter_s3_success = 1U;
134-
if (vm->pm.sx_state_data == NULL) {
135-
pr_err("No Sx state info avaiable. No Sx support");
136-
host_enter_s3_success = 0U;
137-
return;
138-
}
134+
if (vm->pm.sx_state_data != NULL) {
135+
pause_vm(vm); /* pause vm0 before suspend system */
139136

140-
pause_vm(vm); /* pause vm0 before suspend system */
137+
pcpu_id = get_cpu_id();
141138

142-
pcpu_id = get_cpu_id();
139+
/* Save the wakeup vec set by guest. Will return to guest
140+
* with this wakeup vec as entry.
141+
*/
142+
guest_wakeup_vec32 = *vm->pm.sx_state_data->wake_vector_32;
143143

144-
/* Save the wakeup vec set by guest. Will return to guest
145-
* with this wakeup vec as entry.
146-
*/
147-
guest_wakeup_vec32 = *vm->pm.sx_state_data->wake_vector_32;
144+
/* set ACRN wakeup vec instead */
145+
*vm->pm.sx_state_data->wake_vector_32 =
146+
(uint32_t) trampoline_start16_paddr;
148147

149-
/* set ACRN wakeup vec instead */
150-
*vm->pm.sx_state_data->wake_vector_32 =
151-
(uint32_t) trampoline_start16_paddr;
148+
/* offline all APs */
149+
stop_cpus();
152150

153-
/* offline all APs */
154-
stop_cpus();
151+
/* Save default main entry and we will restore it after
152+
* back from S3. So the AP online could jmp to correct
153+
* main entry.
154+
*/
155+
pmain_entry_saved = read_trampoline_sym(main_entry);
155156

156-
/* Save default main entry and we will restore it after
157-
* back from S3. So the AP online could jmp to correct
158-
* main entry.
159-
*/
160-
pmain_entry_saved = read_trampoline_sym(main_entry);
157+
/* Set the main entry for resume from S3 state */
158+
write_trampoline_sym(main_entry, (uint64_t)restore_s3_context);
161159

162-
/* Set the main entry for resume from S3 state */
163-
write_trampoline_sym(main_entry, (uint64_t)restore_s3_context);
160+
CPU_IRQ_DISABLE();
161+
vmx_off(pcpu_id);
164162

165-
CPU_IRQ_DISABLE();
166-
vmx_off(pcpu_id);
163+
suspend_console();
164+
suspend_ioapic();
165+
suspend_iommu();
166+
suspend_lapic();
167167

168-
suspend_console();
169-
suspend_ioapic();
170-
suspend_iommu();
171-
suspend_lapic();
168+
asm_enter_s3(vm, pm1a_cnt_val, pm1b_cnt_val);
172169

173-
asm_enter_s3(vm, pm1a_cnt_val, pm1b_cnt_val);
170+
/* release the lock aquired in trampoline code */
171+
spinlock_release(&trampoline_spinlock);
174172

175-
/* release the lock aquired in trampoline code */
176-
spinlock_release(&trampoline_spinlock);
173+
resume_lapic();
174+
resume_iommu();
175+
resume_ioapic();
176+
resume_console();
177177

178-
resume_lapic();
179-
resume_iommu();
180-
resume_ioapic();
181-
resume_console();
178+
exec_vmxon_instr(pcpu_id);
179+
CPU_IRQ_ENABLE();
182180

183-
exec_vmxon_instr(pcpu_id);
184-
CPU_IRQ_ENABLE();
181+
/* restore the default main entry */
182+
write_trampoline_sym(main_entry, pmain_entry_saved);
185183

186-
/* restore the default main entry */
187-
write_trampoline_sym(main_entry, pmain_entry_saved);
184+
/* online all APs again */
185+
start_cpus();
188186

189-
/* online all APs again */
190-
start_cpus();
187+
/* jump back to vm */
188+
resume_vm_from_s3(vm, guest_wakeup_vec32);
189+
} else {
190+
pr_err("No Sx state info avaiable. No Sx support");
191+
host_enter_s3_success = 0U;
192+
}
191193

192-
/* jump back to vm */
193-
resume_vm_from_s3(vm, guest_wakeup_vec32);
194194

195195
return;
196196
}

hypervisor/arch/x86/trusty.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,22 @@ void destroy_secure_world(struct acrn_vm *vm, bool need_clr_mem)
134134
uint64_t gpa_uos = vm->sworld_control.sworld_memory.base_gpa_in_uos;
135135
uint64_t size = vm->sworld_control.sworld_memory.length;
136136

137-
if (vm->arch_vm.sworld_eptp == NULL) {
138-
pr_err("sworld eptp is NULL, it's not created");
139-
return;
140-
}
141-
142-
if (need_clr_mem) {
143-
/* clear trusty memory space */
144-
(void)memset(hpa2hva(hpa), 0U, (size_t)size);
145-
}
137+
if (vm->arch_vm.sworld_eptp != NULL) {
138+
if (need_clr_mem) {
139+
/* clear trusty memory space */
140+
(void)memset(hpa2hva(hpa), 0U, (size_t)size);
141+
}
146142

147-
ept_mr_del(vm, vm->arch_vm.sworld_eptp, gpa_uos, size);
148-
/* sanitize trusty ept page-structures */
149-
sanitize_pte((uint64_t *)vm->arch_vm.sworld_eptp);
150-
vm->arch_vm.sworld_eptp = NULL;
143+
ept_mr_del(vm, vm->arch_vm.sworld_eptp, gpa_uos, size);
144+
/* sanitize trusty ept page-structures */
145+
sanitize_pte((uint64_t *)vm->arch_vm.sworld_eptp);
146+
vm->arch_vm.sworld_eptp = NULL;
151147

152-
/* Restore memory to guest normal world */
153-
ept_mr_add(vm, vm->arch_vm.nworld_eptp, hpa, gpa_uos, size, EPT_RWX | EPT_WB);
148+
/* Restore memory to guest normal world */
149+
ept_mr_add(vm, vm->arch_vm.nworld_eptp, hpa, gpa_uos, size, EPT_RWX | EPT_WB);
150+
} else {
151+
pr_err("sworld eptp is NULL, it's not created");
152+
}
154153
}
155154

156155
static inline void save_fxstore_guest_area(struct ext_context *ext_ctx)
@@ -497,13 +496,12 @@ void trusty_set_dseed(const void *dseed, uint8_t dseed_num)
497496
g_key_info.num_seeds = 1U;
498497
(void)memset(g_key_info.dseed_list[0].seed, 0xA5U,
499498
sizeof(g_key_info.dseed_list[0].seed));
500-
return;
499+
} else {
500+
g_key_info.num_seeds = dseed_num;
501+
(void)memcpy_s(&g_key_info.dseed_list,
502+
sizeof(struct seed_info) * dseed_num,
503+
dseed, sizeof(struct seed_info) * dseed_num);
501504
}
502-
503-
g_key_info.num_seeds = dseed_num;
504-
(void)memcpy_s(&g_key_info.dseed_list,
505-
sizeof(struct seed_info) * dseed_num,
506-
dseed, sizeof(struct seed_info) * dseed_num);
507505
}
508506

509507
void save_sworld_context(struct acrn_vcpu *vcpu)

hypervisor/include/arch/x86/io.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ static inline void pio_write(uint32_t v, uint16_t addr, size_t sz)
8181

8282
static inline uint32_t pio_read(uint16_t addr, size_t sz)
8383
{
84+
uint32_t ret;
8485
if (sz == 1U) {
85-
return pio_read8(addr);
86-
}
87-
if (sz == 2U) {
88-
return pio_read16(addr);
86+
ret = pio_read8(addr);
87+
} else if (sz == 2U) {
88+
ret = pio_read16(addr);
89+
} else {
90+
ret = pio_read32(addr);
8991
}
90-
return pio_read32(addr);
92+
return ret;
9193
}
9294

9395
/** Writes a 64 bit value to a memory mapped IO device.

0 commit comments

Comments
 (0)