Skip to content

Commit cc1d532

Browse files
mingqiangchijren1
authored andcommitted
add data structure in vm for enable trusty feature
add key info structure add sworld_eptp in vm structure, and rename ept->nworld_eptp add secure world control structure Change-Id: Tracked-On:220921 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
1 parent e91b6aa commit cc1d532

File tree

9 files changed

+166
-19
lines changed

9 files changed

+166
-19
lines changed

hypervisor/arch/x86/ept.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void free_ept_mem(void *pml4_addr)
134134

135135
void destroy_ept(struct vm *vm)
136136
{
137-
free_ept_mem(vm->arch_vm.ept);
137+
free_ept_mem(vm->arch_vm.nworld_eptp);
138138
free_ept_mem(vm->arch_vm.m2p);
139139
}
140140

@@ -147,7 +147,7 @@ uint64_t gpa2hpa_check(struct vm *vm, uint64_t gpa,
147147
struct map_params map_params;
148148

149149
map_params.page_table_type = PT_EPT;
150-
map_params.pml4_base = vm->arch_vm.ept;
150+
map_params.pml4_base = vm->arch_vm.nworld_eptp;
151151
map_params.pml4_inverted = vm->arch_vm.m2p;
152152
obtain_last_page_table_entry(&map_params, &entry,
153153
(void *)gpa, true);
@@ -186,7 +186,7 @@ uint64_t hpa2gpa(struct vm *vm, uint64_t hpa)
186186
struct map_params map_params;
187187

188188
map_params.page_table_type = PT_EPT;
189-
map_params.pml4_base = vm->arch_vm.ept;
189+
map_params.pml4_base = vm->arch_vm.nworld_eptp;
190190
map_params.pml4_inverted = vm->arch_vm.m2p;
191191

192192
obtain_last_page_table_entry(&map_params, &entry,
@@ -536,13 +536,13 @@ int ept_mmap(struct vm *vm, uint64_t hpa,
536536

537537
/* Setup memory map parameters */
538538
map_params.page_table_type = PT_EPT;
539-
if (vm->arch_vm.ept) {
540-
map_params.pml4_base = vm->arch_vm.ept;
539+
if (vm->arch_vm.nworld_eptp) {
540+
map_params.pml4_base = vm->arch_vm.nworld_eptp;
541541
map_params.pml4_inverted = vm->arch_vm.m2p;
542542
} else {
543543
map_params.pml4_base =
544544
alloc_paging_struct();
545-
vm->arch_vm.ept = map_params.pml4_base;
545+
vm->arch_vm.nworld_eptp = map_params.pml4_base;
546546
map_params.pml4_inverted = alloc_paging_struct();
547547
vm->arch_vm.m2p = map_params.pml4_inverted;
548548
}

hypervisor/arch/x86/guest/vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
132132
#endif
133133
} else {
134134
/* populate UOS vm fields according to vm_desc */
135-
vm->secure_world_enabled =
136-
vm_desc->secure_world_enabled;
135+
vm->sworld_control.sworld_enabled =
136+
vm_desc->sworld_enabled;
137137
memcpy_s(&vm->GUID[0], sizeof(vm->GUID),
138138
&vm_desc->GUID[0],
139139
sizeof(vm_desc->GUID));

hypervisor/arch/x86/mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void mmu_invept(struct vcpu *vcpu)
137137
struct invept_desc desc = {0};
138138

139139
if (check_invept_single_support()) {
140-
desc.eptp = (uint64_t) vcpu->vm->arch_vm.ept | (3 << 3) | 6;
140+
desc.eptp = (uint64_t) vcpu->vm->arch_vm.nworld_eptp
141+
| (3 << 3) | 6;
141142
_invept(INVEPT_TYPE_SINGLE_CONTEXT, desc);
142143
} else if (check_invept_global_support())
143144
_invept(INVEPT_TYPE_ALL_CONTEXTS, desc);

hypervisor/arch/x86/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
983983
* TODO: introduce API to make this data driven based
984984
* on VMX_EPT_VPID_CAP
985985
*/
986-
value64 = ((uint64_t) vm->arch_vm.ept) | (3 << 3) | 6;
986+
value64 = ((uint64_t) vm->arch_vm.nworld_eptp) | (3 << 3) | 6;
987987
exec_vmwrite64(VMX_EPT_POINTER_FULL, value64);
988988
pr_dbg("VMX_EPT_POINTER: 0x%016llx ", value64);
989989

hypervisor/common/hypercall.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ int64_t hcall_create_vm(struct vm *vm, uint64_t param)
159159
}
160160

161161
memset(&vm_desc, 0, sizeof(vm_desc));
162-
vm_desc.secure_world_enabled = cv.secure_world_enabled;
162+
vm_desc.sworld_enabled =
163+
(!!(cv.vm_flag & (SECURE_WORLD_ENABLED)));
163164
memcpy_s(&vm_desc.GUID[0], 16, &cv.GUID[0], 16);
164165
ret = create_vm(&vm_desc, &target_vm);
165166

@@ -541,10 +542,10 @@ int64_t hcall_assign_ptdev(struct vm *vm, uint64_t vmid, uint64_t param)
541542

542543
/* create a iommu domain for target VM if not created */
543544
if (!target_vm->iommu_domain) {
544-
ASSERT(target_vm->arch_vm.ept, "EPT of VM not set!");
545+
ASSERT(target_vm->arch_vm.nworld_eptp, "EPT of VM not set!");
545546
/* TODO: how to get vm's address width? */
546547
target_vm->iommu_domain = create_iommu_domain(vmid,
547-
target_vm->arch_vm.ept, 48);
548+
target_vm->arch_vm.nworld_eptp, 48);
548549
ASSERT(target_vm->iommu_domain,
549550
"failed to created iommu domain!");
550551
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ struct vm_state_info {
109109

110110
struct vm_arch {
111111
void *guest_pml4; /* Guest pml4 */
112-
void *ept; /* EPT hierarchy */
112+
/* EPT hierarchy for Normal World */
113+
void *nworld_eptp;
114+
/* EPT hierarchy for Secure World
115+
* Secure world can access Normal World's memory,
116+
* but Normal World can not access Secure World's memory.
117+
*/
118+
void *sworld_eptp;
113119
void *m2p; /* machine address to guest physical address */
114120
void *tmp_pg_array; /* Page array for tmp guest paging struct */
115121
void *iobitmap[2];/* IO bitmap page array base address for this VM */
@@ -160,7 +166,7 @@ struct vm {
160166
spinlock_t ptdev_lock;
161167

162168
unsigned char GUID[16];
163-
unsigned int secure_world_enabled;
169+
struct secure_world_control sworld_control;
164170
};
165171

166172
struct vm_description {
@@ -178,7 +184,8 @@ struct vm_description {
178184
bool vm_created;
179185
/* Index indicating VM's privilege level */
180186
unsigned int vm_state_info_privilege;
181-
unsigned int secure_world_enabled; /* secure_world enabled? */
187+
/* Whether secure world is enabled for current VM. */
188+
bool sworld_enabled;
182189
};
183190

184191
struct vm_description_array {

hypervisor/include/arch/x86/hv_arch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <msr.h>
4141
#include <io.h>
4242
#include <vcpu.h>
43+
#include <trusty.h>
4344
#include <vm.h>
4445
#include <cpuid.h>
4546
#include <mmu.h>

hypervisor/include/arch/x86/trusty.h

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Intel Corporation nor the names of its
15+
* contributors may be used to endorse or promote products derived
16+
* from this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef TRUSTY_H_
32+
#define TRUSTY_H_
33+
34+
#define BOOTLOADER_SEED_MAX_ENTRIES 10
35+
#define RPMB_MAX_PARTITION_NUMBER 6
36+
#define MMC_PROD_NAME_WITH_PSN_LEN 15
37+
#define BUP_MKHI_BOOTLOADER_SEED_LEN 64
38+
39+
/* Structure of seed info */
40+
struct seed_info {
41+
uint8_t cse_svn;
42+
uint8_t bios_svn;
43+
uint8_t padding[2];
44+
uint8_t seed[BUP_MKHI_BOOTLOADER_SEED_LEN];
45+
};
46+
47+
/* Structure of key info */
48+
struct key_info {
49+
uint32_t size_of_this_struct;
50+
51+
/* version info:
52+
0: baseline structure
53+
1: add ** new field
54+
*/
55+
uint32_t version;
56+
57+
/* platform:
58+
0: Dummy (fake secret)
59+
1: APL (APL + ABL)
60+
2: ICL (ICL + SBL)
61+
3: CWP (APL|ICL + SBL + CWP)
62+
4: Brillo (Android Things)
63+
*/
64+
uint32_t platform;
65+
66+
/* flags info:
67+
Bit 0: manufacturing state (0:manufacturing done;
68+
1:in manufacturing mode)
69+
Bit 1: secure boot state (0:disabled; 1: enabled)
70+
Bit 2: test seeds (ICL only - 0:production seeds; 1: test seeds)
71+
other bits all reserved as 0
72+
*/
73+
uint32_t flags;
74+
75+
/* Keep 64-bit align */
76+
uint32_t pad1;
77+
78+
/* Seed list, include useeds(user seeds) and dseed(device seeds) */
79+
uint32_t num_seeds;
80+
struct seed_info useed_list[BOOTLOADER_SEED_MAX_ENTRIES];
81+
struct seed_info dseed_list[BOOTLOADER_SEED_MAX_ENTRIES];
82+
83+
/* For ICL+ */
84+
/* rpmb keys, Currently HMAC-SHA256 is used in RPMB spec
85+
* and 256-bit (32byte) is enough. Hence only lower 32 bytes will be
86+
* used for now for each entry. But keep higher 32 bytes for future
87+
* extension. Note that, RPMB keys are already tied to storage device
88+
* serial number.If there are multiple RPMB partitions, then we will
89+
* get multiple available RPMB keys. And if rpmb_key[n][64] == 0,
90+
* then the n-th RPMB key is unavailable (Either because of no such
91+
* RPMB partition, or because OSloader doesn't want to share
92+
* the n-th RPMB key with Trusty)
93+
*/
94+
uint8_t rpmb_key[RPMB_MAX_PARTITION_NUMBER][64];
95+
96+
/* 256-bit AES encryption key to encrypt/decrypt attestation keybox,
97+
this key should be derived from a fixed key which is RPMB seed.
98+
RPMB key (HMAC key) and this encryption key (AES key) are both
99+
derived from the same RPMB seed.
100+
*/
101+
uint8_t attkb_enc_key[32];
102+
103+
/* For APL only */
104+
/* RPMB key is derived with dseed together with this serial number,
105+
* for ICL +, CSE directly provides the rpmb_key which is already
106+
* tied to serial number. Concatenation of emmc product name
107+
* with a string representation of PSN
108+
*/
109+
char serial[MMC_PROD_NAME_WITH_PSN_LEN];
110+
char pad2;
111+
};
112+
113+
struct secure_world_memory {
114+
/* The secure world base address of GPA in SOS */
115+
uint64_t base_gpa;
116+
/* The secure world base address of HPA */
117+
uint64_t base_hpa;
118+
/* Secure world runtime memory size */
119+
uint64_t length;
120+
};
121+
122+
struct secure_world_control {
123+
/* Whether secure world is enabled for current VM */
124+
bool sworld_enabled;
125+
/* key info structure */
126+
struct key_info key_info;
127+
/* Secure world memory structure */
128+
struct secure_world_memory sworld_memory;
129+
};
130+
131+
#endif /* TRUSTY_H_ */
132+

hypervisor/include/public/acrn_common.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
#define REQUEST_READ 0
6464
#define REQUEST_WRITE 1
6565

66+
/* Generic VM flags from guest OS */
67+
#define SECURE_WORLD_ENABLED (1<<0) /* Whether secure world is enabled */
68+
6669
/**
6770
* @brief Hypercall
6871
*
@@ -148,11 +151,13 @@ struct acrn_create_vm {
148151
/** the GUID of this VM */
149152
uint8_t GUID[16];
150153

151-
/** whether Secure World is enabled for this VM */
152-
uint8_t secure_world_enabled;
154+
/* VM flag bits from Guest OS, now used
155+
* SECURE_WORLD_ENABLED (1<<0)
156+
*/
157+
uint64_t vm_flag;
153158

154159
/** Reserved for future use*/
155-
uint8_t reserved[31];
160+
uint8_t reserved[24];
156161
} __aligned(8);
157162

158163
/**

0 commit comments

Comments
 (0)