Add a sub-test to verify that an exception on EENTER is correctly reported. Although the type of exception doesn't truly matter, e.g. a page fault (#PF) is no more or less interesting than a general protection fault (#GP), use an unaligned TCS to trigger a #GP to avoid errors on platforms that report EPCM related #PFs as #GPs, e.g. SGX1 systems. Suggested-by: Cedric Xing <cedric.xing@xxxxxxxxx> Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> --- tools/testing/selftests/x86/sgx/defines.h | 4 ++++ tools/testing/selftests/x86/sgx/main.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/tools/testing/selftests/x86/sgx/defines.h b/tools/testing/selftests/x86/sgx/defines.h index 3ff73a9d9b93..ab9671b8a993 100644 --- a/tools/testing/selftests/x86/sgx/defines.h +++ b/tools/testing/selftests/x86/sgx/defines.h @@ -36,4 +36,8 @@ typedef uint64_t u64; #include "../../../../../arch/x86/kernel/cpu/sgx/arch.h" #include "../../../../../arch/x86/include/uapi/asm/sgx.h" +#define ENCLU_EENTER 2 + +#define GP_VECTOR 13 + #endif /* TYPES_H */ diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c index 93b8d7781782..2676570493f2 100644 --- a/tools/testing/selftests/x86/sgx/main.c +++ b/tools/testing/selftests/x86/sgx/main.c @@ -321,6 +321,12 @@ static void test_vdso_no_exit_handler(struct sgx_secs *secs) sgx_call((void *)&MAGIC, &result, 0, 0, 0, 0, (void *)secs->base, &exception, NULL); ASSERT_EQ(result, MAGIC); + + /* Verify a #GP is reported if the TCS isn't 4k aligned. */ + sgx_call((void *)&MAGIC, &result, 0, 0, 0, 0, + (void *)(secs->base | 0xfff), &exception, NULL); + ASSERT_EQ(exception.trapnr, GP_VECTOR); + ASSERT_EQ(exception.leaf, ENCLU_EENTER); } int main(int argc, char *argv[], char *envp[]) -- 2.22.0