Skip to content

Commit b5b769f

Browse files
YadongQilijinxia
authored andcommitted
HV: trusty: refine secure_world_control
Define Bitmap flag to indicate secure world's state: supported: 0(not supported), 1(supported) active: 0(inactive), 1(active) Refine secure_world_memory: base_gpa_in_sos: base_gpa from SOS's view base_gpa_in_uos: base_gpa from UOS's view, this is the original base_gpa allocated by bootloader. Recording above GPA is for usage of trusty EPT destroy and re-create. There is an assumption: the secure world's memory address is contiguous in both SOS and physical side. Signed-off-by: Qi Yadong <yadong.qi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent ff96453 commit b5b769f

File tree

9 files changed

+37
-28
lines changed

9 files changed

+37
-28
lines changed

hypervisor/arch/x86/ept.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ void destroy_ept(struct vm *vm)
106106
* - trusty is enabled. But not initialized yet.
107107
* Check vm->arch_vm.sworld_eptp.
108108
*/
109-
if (vm->sworld_control.sworld_enabled &&
110-
(vm->arch_vm.sworld_eptp != NULL)) {
111-
free_ept_mem(vm->arch_vm.sworld_eptp);
109+
if (vm->sworld_control.flag.active) {
110+
free_ept_mem(HPA2HVA(vm->arch_vm.sworld_eptp));
112111
vm->arch_vm.sworld_eptp = NULL;
113112
}
114113
}

hypervisor/arch/x86/guest/guest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ uint64_t create_guest_initial_paging(struct vm *vm)
804804
* FIXME: this is a tempory solution for trusty enabling,
805805
* the final solution is that vSBL will setup guest page tables
806806
*/
807-
if (vm->sworld_control.sworld_enabled && !is_vm0(vm)) {
807+
if (vm->sworld_control.flag.supported && !is_vm0(vm)) {
808808
/* clear page entry for trusty */
809809
(void)memset(pml4_addr + 6U * PAGE_SIZE_4K, 0U, PAGE_SIZE_4K);
810810

hypervisor/arch/x86/guest/vm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
156156
#endif
157157
} else {
158158
/* populate UOS vm fields according to vm_desc */
159-
vm->sworld_control.sworld_enabled =
160-
vm_desc->sworld_enabled;
159+
vm->sworld_control.flag.supported =
160+
vm_desc->sworld_supported;
161161
(void)memcpy_s(&vm->GUID[0], sizeof(vm->GUID),
162162
&vm_desc->GUID[0],
163163
sizeof(vm_desc->GUID));
@@ -266,7 +266,7 @@ int shutdown_vm(struct vm *vm)
266266
vioapic_cleanup(vm->arch_vm.virt_ioapic);
267267

268268
/* Destroy secure world */
269-
if (vm->sworld_control.sworld_enabled) {
269+
if (vm->sworld_control.flag.active) {
270270
destroy_secure_world(vm);
271271
}
272272
/* Free EPT allocated resources assigned to VM */

hypervisor/arch/x86/mmu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ void invept(struct vcpu *vcpu)
175175
desc.eptp = HVA2HPA(vcpu->vm->arch_vm.nworld_eptp) |
176176
(3UL << 3U) | 6UL;
177177
local_invept(INVEPT_TYPE_SINGLE_CONTEXT, desc);
178-
if (vcpu->vm->sworld_control.sworld_enabled &&
179-
vcpu->vm->arch_vm.sworld_eptp != NULL) {
178+
if (vcpu->vm->sworld_control.flag.active) {
180179
desc.eptp = HVA2HPA(vcpu->vm->arch_vm.sworld_eptp)
181180
| (3UL << 3U) | 6UL;
182181
local_invept(INVEPT_TYPE_SINGLE_CONTEXT, desc);

hypervisor/arch/x86/trusty.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
9292
return;
9393
}
9494

95-
if (!vm->sworld_control.sworld_enabled
95+
if (!vm->sworld_control.flag.supported
9696
|| vm->arch_vm.sworld_eptp != NULL) {
97-
pr_err("Sworld is not enabled or Sworld eptp is not NULL");
97+
pr_err("Sworld is not supported or Sworld eptp is not NULL");
9898
return;
9999
}
100100

@@ -164,8 +164,9 @@ static void create_secure_world_ept(struct vm *vm, uint64_t gpa_orig,
164164
gpa, size);
165165

166166
/* Backup secure world info, will be used when
167-
* destroy secure world */
168-
vm->sworld_control.sworld_memory.base_gpa = gpa;
167+
* destroy secure world and suspend UOS */
168+
vm->sworld_control.sworld_memory.base_gpa_in_sos = gpa;
169+
vm->sworld_control.sworld_memory.base_gpa_in_uos = gpa_orig;
169170
vm->sworld_control.sworld_memory.base_hpa = hpa;
170171
vm->sworld_control.sworld_memory.length = size;
171172

@@ -194,7 +195,7 @@ void destroy_secure_world(struct vm *vm)
194195
map_params.pml4_inverted = vm0->arch_vm.m2p;
195196

196197
map_mem(&map_params, (void *)vm->sworld_control.sworld_memory.base_hpa,
197-
(void *)vm->sworld_control.sworld_memory.base_gpa,
198+
(void *)vm->sworld_control.sworld_memory.base_gpa_in_sos,
198199
vm->sworld_control.sworld_memory.length,
199200
(IA32E_EPT_R_BIT |
200201
IA32E_EPT_W_BIT |

hypervisor/common/hypercall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ int32_t hcall_create_vm(struct vm *vm, uint64_t param)
181181
}
182182

183183
(void)memset(&vm_desc, 0U, sizeof(vm_desc));
184-
vm_desc.sworld_enabled =
184+
vm_desc.sworld_supported =
185185
((cv.vm_flag & (SECURE_WORLD_ENABLED)) != 0U);
186186
(void)memcpy_s(&vm_desc.GUID[0], 16U, &cv.GUID[0], 16U);
187187
ret = create_vm(&vm_desc, &target_vm);

hypervisor/common/trusty_hypercall.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ int32_t hcall_world_switch(struct vcpu *vcpu)
2020
return -EINVAL;
2121
}
2222

23-
if (!vcpu->vm->sworld_control.sworld_enabled) {
24-
pr_err("%s, Secure World is not enabled!\n", __func__);
23+
if (!vcpu->vm->sworld_control.flag.supported) {
24+
pr_err("Secure World is not supported!\n");
2525
return -EPERM;
2626
}
2727

28-
if (vcpu->vm->arch_vm.sworld_eptp == NULL) {
29-
pr_err("%s, Trusty is not initialized!\n", __func__);
28+
if (!vcpu->vm->sworld_control.flag.active) {
29+
pr_err("Trusty is not initialized!\n");
3030
return -EPERM;
3131
}
3232

@@ -39,13 +39,13 @@ int32_t hcall_world_switch(struct vcpu *vcpu)
3939
*/
4040
int32_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
4141
{
42-
if (!vcpu->vm->sworld_control.sworld_enabled) {
43-
pr_err("%s, Secure World is not enabled!\n", __func__);
42+
if (!vcpu->vm->sworld_control.flag.supported) {
43+
pr_err("Secure World is not supported!\n");
4444
return -EPERM;
4545
}
4646

47-
if (vcpu->vm->arch_vm.sworld_eptp != NULL) {
48-
pr_err("%s, Trusty already initialized!\n", __func__);
47+
if (vcpu->vm->sworld_control.flag.active) {
48+
pr_err("Trusty already initialized!\n");
4949
return -EPERM;
5050
}
5151

@@ -59,5 +59,7 @@ int32_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
5959
return -ENODEV;
6060
}
6161

62+
vcpu->vm->sworld_control.flag.active = 1UL;
63+
6264
return 0;
6365
}

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ struct vm_description {
167167
uint16_t *vm_pcpu_ids;
168168
unsigned char GUID[16]; /* GUID of the vm will be created */
169169
uint16_t vm_hw_num_cores; /* Number of virtual cores */
170-
/* Whether secure world is enabled for current VM. */
171-
bool sworld_enabled;
170+
/* Whether secure world is supported for current VM. */
171+
bool sworld_supported;
172172
#ifdef CONFIG_PARTITION_MODE
173173
uint8_t vm_id;
174174
struct mptable_info *mptable;

hypervisor/include/arch/x86/trusty.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,24 @@ struct trusty_key_info {
9292

9393
struct secure_world_memory {
9494
/* The secure world base address of GPA in SOS */
95-
uint64_t base_gpa;
95+
uint64_t base_gpa_in_sos;
96+
/* The original secure world base address allocated by bootloader */
97+
uint64_t base_gpa_in_uos;
9698
/* The secure world base address of HPA */
9799
uint64_t base_hpa;
98100
/* Secure world runtime memory size */
99101
uint64_t length;
100102
};
101103

102104
struct secure_world_control {
103-
/* Whether secure world is enabled for current VM */
104-
bool sworld_enabled;
105+
/* Flag indicates Secure World's state */
106+
struct {
107+
/* secure world supporting: 0(unsupported), 1(supported) */
108+
uint64_t supported : 1;
109+
/* secure world running status: 0(inactive), 1(active) */
110+
uint64_t active : 1;
111+
uint64_t reserved : 62;
112+
} flag;
105113
/* Secure world memory structure */
106114
struct secure_world_memory sworld_memory;
107115
};

0 commit comments

Comments
 (0)