Skip to content

Commit b564982

Browse files
rchatrehansendc
authored andcommitted
selftests/sgx: Introduce TCS initialization enclave operation
The Thread Control Structure (TCS) contains meta-data used by the hardware to save and restore thread specific information when entering/exiting the enclave. A TCS can be added to an initialized enclave by first adding a new regular enclave page, initializing the content of the new page from within the enclave, and then changing that page's type to a TCS. Support the initialization of a TCS from within the enclave. The variable information needed that should be provided from outside the enclave is the address of the TCS, address of the State Save Area (SSA), and the entry point that the thread should use to enter the enclave. With this information provided all needed fields of a TCS can be initialized. Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Acked-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lkml.kernel.org/r/bad6052056188bde753a54313da1ac8f1e29088a.1652137848.git.reinette.chatre@intel.com
1 parent 7eb4370 commit b564982

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tools/testing/selftests/sgx/defines.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum encl_op_type {
2626
ENCL_OP_NOP,
2727
ENCL_OP_EACCEPT,
2828
ENCL_OP_EMODPE,
29+
ENCL_OP_INIT_TCS_PAGE,
2930
ENCL_OP_MAX,
3031
};
3132

@@ -68,4 +69,11 @@ struct encl_op_emodpe {
6869
uint64_t flags;
6970
};
7071

72+
struct encl_op_init_tcs_page {
73+
struct encl_op_header header;
74+
uint64_t tcs_page;
75+
uint64_t ssa;
76+
uint64_t entry;
77+
};
78+
7179
#endif /* DEFINES_H */

tools/testing/selftests/sgx/test_encl.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ static void *memcpy(void *dest, const void *src, size_t n)
5757
return dest;
5858
}
5959

60+
static void *memset(void *dest, int c, size_t n)
61+
{
62+
size_t i;
63+
64+
for (i = 0; i < n; i++)
65+
((char *)dest)[i] = c;
66+
67+
return dest;
68+
}
69+
70+
static void do_encl_init_tcs_page(void *_op)
71+
{
72+
struct encl_op_init_tcs_page *op = _op;
73+
void *tcs = (void *)op->tcs_page;
74+
uint32_t val_32;
75+
76+
memset(tcs, 0, 16); /* STATE and FLAGS */
77+
memcpy(tcs + 16, &op->ssa, 8); /* OSSA */
78+
memset(tcs + 24, 0, 4); /* CSSA */
79+
val_32 = 1;
80+
memcpy(tcs + 28, &val_32, 4); /* NSSA */
81+
memcpy(tcs + 32, &op->entry, 8); /* OENTRY */
82+
memset(tcs + 40, 0, 24); /* AEP, OFSBASE, OGSBASE */
83+
val_32 = 0xFFFFFFFF;
84+
memcpy(tcs + 64, &val_32, 4); /* FSLIMIT */
85+
memcpy(tcs + 68, &val_32, 4); /* GSLIMIT */
86+
memset(tcs + 72, 0, 4024); /* Reserved */
87+
}
88+
6089
static void do_encl_op_put_to_buf(void *op)
6190
{
6291
struct encl_op_put_to_buf *op2 = op;
@@ -100,6 +129,7 @@ void encl_body(void *rdi, void *rsi)
100129
do_encl_op_nop,
101130
do_encl_eaccept,
102131
do_encl_emodpe,
132+
do_encl_init_tcs_page,
103133
};
104134

105135
struct encl_op_header *op = (struct encl_op_header *)rdi;

0 commit comments

Comments
 (0)