Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Reinette Chatre and committed by
Dave Hansen
b564982f 7eb43701

+38
+8
tools/testing/selftests/sgx/defines.h
··· 26 26 ENCL_OP_NOP, 27 27 ENCL_OP_EACCEPT, 28 28 ENCL_OP_EMODPE, 29 + ENCL_OP_INIT_TCS_PAGE, 29 30 ENCL_OP_MAX, 30 31 }; 31 32 ··· 67 66 struct encl_op_header header; 68 67 uint64_t epc_addr; 69 68 uint64_t flags; 69 + }; 70 + 71 + struct encl_op_init_tcs_page { 72 + struct encl_op_header header; 73 + uint64_t tcs_page; 74 + uint64_t ssa; 75 + uint64_t entry; 70 76 }; 71 77 72 78 #endif /* DEFINES_H */
+30
tools/testing/selftests/sgx/test_encl.c
··· 57 57 return dest; 58 58 } 59 59 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 + 60 89 static void do_encl_op_put_to_buf(void *op) 61 90 { 62 91 struct encl_op_put_to_buf *op2 = op; ··· 129 100 do_encl_op_nop, 130 101 do_encl_eaccept, 131 102 do_encl_emodpe, 103 + do_encl_init_tcs_page, 132 104 }; 133 105 134 106 struct encl_op_header *op = (struct encl_op_header *)rdi;