@@ -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 */
@@ -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[])
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@intel.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> --- tools/testing/selftests/x86/sgx/defines.h | 4 ++++ tools/testing/selftests/x86/sgx/main.c | 6 ++++++ 2 files changed, 10 insertions(+)