Skip to content

Commit 688542e

Browse files
rchatrehansendc
authored andcommitted
selftests/sgx: Add test for multiple TCS entry
Each thread executing in an enclave is associated with a Thread Control Structure (TCS). The SGX test enclave contains two hardcoded TCS, thus supporting two threads in the enclave. Add a test to ensure it is possible to enter enclave at both entrypoints. Signed-off-by: Reinette Chatre <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Acked-by: Dave Hansen <[email protected]> Link: https://lkml.kernel.org/r/7be151a57b4c7959a2364753b995e0006efa3da1.1636997631.git.reinette.chatre@intel.com
1 parent 26e688f commit 688542e

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

tools/testing/selftests/sgx/defines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum encl_op_type {
2323
ENCL_OP_GET_FROM_BUFFER,
2424
ENCL_OP_PUT_TO_ADDRESS,
2525
ENCL_OP_GET_FROM_ADDRESS,
26+
ENCL_OP_NOP,
2627
ENCL_OP_MAX,
2728
};
2829

tools/testing/selftests/sgx/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,38 @@ TEST_F(enclave, clobbered_vdso_and_user_function)
409409
EXPECT_EQ(self->run.user_data, 0);
410410
}
411411

412+
/*
413+
* Sanity check that it is possible to enter either of the two hardcoded TCS
414+
*/
415+
TEST_F(enclave, tcs_entry)
416+
{
417+
struct encl_op_header op;
418+
419+
ASSERT_TRUE(setup_test_encl(ENCL_HEAP_SIZE_DEFAULT, &self->encl, _metadata));
420+
421+
memset(&self->run, 0, sizeof(self->run));
422+
self->run.tcs = self->encl.encl_base;
423+
424+
op.type = ENCL_OP_NOP;
425+
426+
EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0);
427+
428+
EXPECT_EEXIT(&self->run);
429+
EXPECT_EQ(self->run.exception_vector, 0);
430+
EXPECT_EQ(self->run.exception_error_code, 0);
431+
EXPECT_EQ(self->run.exception_addr, 0);
432+
433+
/* Move to the next TCS. */
434+
self->run.tcs = self->encl.encl_base + PAGE_SIZE;
435+
436+
EXPECT_EQ(ENCL_CALL(&op, &self->run, true), 0);
437+
438+
EXPECT_EEXIT(&self->run);
439+
EXPECT_EQ(self->run.exception_vector, 0);
440+
EXPECT_EQ(self->run.exception_error_code, 0);
441+
EXPECT_EQ(self->run.exception_addr, 0);
442+
}
443+
412444
/*
413445
* Second page of .data segment is used to test changing PTE permissions.
414446
* This spans the local encl_buffer within the test enclave.

tools/testing/selftests/sgx/test_encl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@ static void do_encl_op_get_from_addr(void *_op)
4949
memcpy(&op->value, (void *)op->addr, 8);
5050
}
5151

52+
static void do_encl_op_nop(void *_op)
53+
{
54+
55+
}
56+
5257
void encl_body(void *rdi, void *rsi)
5358
{
5459
const void (*encl_op_array[ENCL_OP_MAX])(void *) = {
5560
do_encl_op_put_to_buf,
5661
do_encl_op_get_from_buf,
5762
do_encl_op_put_to_addr,
5863
do_encl_op_get_from_addr,
64+
do_encl_op_nop,
5965
};
6066

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

0 commit comments

Comments
 (0)