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

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 <reinette.chatre@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lkml.kernel.org/r/7be151a57b4c7959a2364753b995e0006efa3da1.1636997631.git.reinette.chatre@intel.com

authored by

Reinette Chatre and committed by
Dave Hansen
688542e2 26e688f1

+39
+1
tools/testing/selftests/sgx/defines.h
··· 23 23 ENCL_OP_GET_FROM_BUFFER, 24 24 ENCL_OP_PUT_TO_ADDRESS, 25 25 ENCL_OP_GET_FROM_ADDRESS, 26 + ENCL_OP_NOP, 26 27 ENCL_OP_MAX, 27 28 }; 28 29
+32
tools/testing/selftests/sgx/main.c
··· 410 410 } 411 411 412 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 + 444 + /* 413 445 * Second page of .data segment is used to test changing PTE permissions. 414 446 * This spans the local encl_buffer within the test enclave. 415 447 *
+6
tools/testing/selftests/sgx/test_encl.c
··· 49 49 memcpy(&op->value, (void *)op->addr, 8); 50 50 } 51 51 52 + static void do_encl_op_nop(void *_op) 53 + { 54 + 55 + } 56 + 52 57 void encl_body(void *rdi, void *rsi) 53 58 { 54 59 const void (*encl_op_array[ENCL_OP_MAX])(void *) = { ··· 61 56 do_encl_op_get_from_buf, 62 57 do_encl_op_put_to_addr, 63 58 do_encl_op_get_from_addr, 59 + do_encl_op_nop, 64 60 }; 65 61 66 62 struct encl_op_header *op = (struct encl_op_header *)rdi;