mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-28 08:16:54 +00:00
hv: coding style: refine initialize_trusty to one exit
1) Move data copy out of initialize_trusty 2) Fix procedure has more than one exit point Tracked-On: #2120 Signed-off-by: Li, Fei1 <fei1.li@intel.com>
This commit is contained in:
parent
8a55f03823
commit
1dca17cd29
@ -443,65 +443,58 @@ static bool init_secure_world_env(struct acrn_vcpu *vcpu,
|
|||||||
return setup_trusty_info(vcpu, size, base_hpa);
|
return setup_trusty_info(vcpu, size, base_hpa);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param)
|
bool initialize_trusty(struct acrn_vcpu *vcpu, const struct trusty_boot_param *boot_param)
|
||||||
{
|
{
|
||||||
|
bool ret = true;
|
||||||
uint64_t trusty_entry_gpa, trusty_base_gpa, trusty_base_hpa;
|
uint64_t trusty_entry_gpa, trusty_base_gpa, trusty_base_hpa;
|
||||||
uint32_t trusty_mem_size;
|
uint32_t trusty_mem_size;
|
||||||
struct acrn_vm *vm = vcpu->vm;
|
struct acrn_vm *vm = vcpu->vm;
|
||||||
struct trusty_boot_param boot_param;
|
|
||||||
|
|
||||||
(void)memset(&boot_param, 0U, sizeof(boot_param));
|
switch (boot_param->version) {
|
||||||
if (copy_from_gpa(vcpu->vm, &boot_param, param, sizeof(boot_param))
|
|
||||||
!= 0) {
|
|
||||||
pr_err("%s: Unable to copy trusty_boot_param\n", __func__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (boot_param.version) {
|
|
||||||
case TRUSTY_VERSION_2:
|
case TRUSTY_VERSION_2:
|
||||||
trusty_entry_gpa = ((uint64_t)boot_param.entry_point) |
|
trusty_entry_gpa = ((uint64_t)boot_param->entry_point) |
|
||||||
(((uint64_t)boot_param.entry_point_high) << 32U);
|
(((uint64_t)boot_param->entry_point_high) << 32U);
|
||||||
trusty_base_gpa = ((uint64_t)boot_param.base_addr) |
|
trusty_base_gpa = ((uint64_t)boot_param->base_addr) |
|
||||||
(((uint64_t)boot_param.base_addr_high) << 32U);
|
(((uint64_t)boot_param->base_addr_high) << 32U);
|
||||||
|
|
||||||
/* copy rpmb_key from OSloader */
|
/* copy rpmb_key from OSloader */
|
||||||
(void)memcpy_s(&g_key_info.rpmb_key[0][0], 64U,
|
(void)memcpy_s(&g_key_info.rpmb_key[0][0], 64U, &boot_param->rpmb_key[0], 64U);
|
||||||
&boot_param.rpmb_key[0], 64U);
|
|
||||||
(void)memset(&boot_param.rpmb_key[0], 0U, 64U);
|
|
||||||
break;
|
break;
|
||||||
case TRUSTY_VERSION:
|
case TRUSTY_VERSION:
|
||||||
trusty_entry_gpa = (uint64_t)boot_param.entry_point;
|
trusty_entry_gpa = (uint64_t)boot_param->entry_point;
|
||||||
trusty_base_gpa = (uint64_t)boot_param.base_addr;
|
trusty_base_gpa = (uint64_t)boot_param->base_addr;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_dbg(ACRN_DBG_TRUSTY, "%s: Version(%u) not supported!\n",
|
pr_err("%s: Version(%u) not supported!\n", __func__, boot_param->version);
|
||||||
__func__, boot_param.version);
|
ret = false;
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
trusty_mem_size = boot_param.mem_size;
|
if (ret == true) {
|
||||||
|
trusty_mem_size = boot_param->mem_size;
|
||||||
|
create_secure_world_ept(vm, trusty_base_gpa, trusty_mem_size,
|
||||||
|
TRUSTY_EPT_REBASE_GPA);
|
||||||
|
trusty_base_hpa = vm->sworld_control.sworld_memory.base_hpa;
|
||||||
|
|
||||||
create_secure_world_ept(vm, trusty_base_gpa, trusty_mem_size,
|
exec_vmwrite64(VMX_EPT_POINTER_FULL,
|
||||||
TRUSTY_EPT_REBASE_GPA);
|
hva2hpa(vm->arch_vm.sworld_eptp) | (3UL << 3U) | 0x6UL);
|
||||||
trusty_base_hpa = vm->sworld_control.sworld_memory.base_hpa;
|
|
||||||
|
|
||||||
exec_vmwrite64(VMX_EPT_POINTER_FULL,
|
/* save Normal World context */
|
||||||
hva2hpa(vm->arch_vm.sworld_eptp) | (3UL << 3U) | 0x6UL);
|
save_world_ctx(vcpu, &vcpu->arch.contexts[NORMAL_WORLD].ext_ctx);
|
||||||
|
|
||||||
/* save Normal World context */
|
/* init secure world environment */
|
||||||
save_world_ctx(vcpu, &vcpu->arch.contexts[NORMAL_WORLD].ext_ctx);
|
if (init_secure_world_env(vcpu,
|
||||||
|
(trusty_entry_gpa - trusty_base_gpa) + TRUSTY_EPT_REBASE_GPA,
|
||||||
|
trusty_base_hpa, trusty_mem_size)) {
|
||||||
|
|
||||||
/* init secure world environment */
|
/* switch to Secure World */
|
||||||
if (init_secure_world_env(vcpu,
|
vcpu->arch.cur_context = SECURE_WORLD;
|
||||||
(trusty_entry_gpa - trusty_base_gpa) + TRUSTY_EPT_REBASE_GPA,
|
} else {
|
||||||
trusty_base_hpa, trusty_mem_size)) {
|
ret = false;
|
||||||
|
}
|
||||||
/* switch to Secure World */
|
|
||||||
vcpu->arch.cur_context = SECURE_WORLD;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void trusty_set_dseed(const void *dseed, uint8_t dseed_num)
|
void trusty_set_dseed(const void *dseed, uint8_t dseed_num)
|
||||||
|
@ -67,6 +67,7 @@ int32_t hcall_world_switch(struct acrn_vcpu *vcpu)
|
|||||||
int32_t hcall_initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param)
|
int32_t hcall_initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param)
|
||||||
{
|
{
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
struct trusty_boot_param boot_param;
|
||||||
|
|
||||||
if (vcpu->vm->sworld_control.flag.supported == 0UL) {
|
if (vcpu->vm->sworld_control.flag.supported == 0UL) {
|
||||||
pr_err("Secure World is not supported!\n");
|
pr_err("Secure World is not supported!\n");
|
||||||
@ -78,7 +79,11 @@ int32_t hcall_initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param)
|
|||||||
pr_err("%s, must initialize Trusty from Normal World!\n", __func__);
|
pr_err("%s, must initialize Trusty from Normal World!\n", __func__);
|
||||||
ret = -EPERM;
|
ret = -EPERM;
|
||||||
} else {
|
} else {
|
||||||
if (!initialize_trusty(vcpu, param)) {
|
(void)memset(&boot_param, 0U, sizeof(boot_param));
|
||||||
|
if (copy_from_gpa(vcpu->vm, &boot_param, param, sizeof(boot_param)) != 0) {
|
||||||
|
pr_err("%s: Unable to copy trusty_boot_param\n", __func__);
|
||||||
|
ret = -EFAULT;
|
||||||
|
} else if (!initialize_trusty(vcpu, &boot_param)) {
|
||||||
ret = -ENODEV;
|
ret = -ENODEV;
|
||||||
} else {
|
} else {
|
||||||
vcpu->vm->sworld_control.flag.active = 1UL;
|
vcpu->vm->sworld_control.flag.active = 1UL;
|
||||||
|
@ -127,7 +127,7 @@ struct trusty_startup_param {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void switch_world(struct acrn_vcpu *vcpu, int32_t next_world);
|
void switch_world(struct acrn_vcpu *vcpu, int32_t next_world);
|
||||||
bool initialize_trusty(struct acrn_vcpu *vcpu, uint64_t param);
|
bool initialize_trusty(struct acrn_vcpu *vcpu, const struct trusty_boot_param *boot_param);
|
||||||
void destroy_secure_world(struct acrn_vm *vm, bool need_clr_mem);
|
void destroy_secure_world(struct acrn_vm *vm, bool need_clr_mem);
|
||||||
void save_sworld_context(struct acrn_vcpu *vcpu);
|
void save_sworld_context(struct acrn_vcpu *vcpu);
|
||||||
void restore_sworld_context(struct acrn_vcpu *vcpu);
|
void restore_sworld_context(struct acrn_vcpu *vcpu);
|
||||||
|
Loading…
Reference in New Issue
Block a user