@@ -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 /* DEFINES_H */
@@ -334,6 +334,12 @@ static void test_sgx_vdso(struct sgx_secs *secs)
sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL,
(void *)secs->base, &exception, NULL);
EXPECT_EQ(result, MAGIC);
+
+ /* Verify a #GP is reported if the TCS isn't 4k aligned. */
+ sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL,
+ (void *)(secs->base | 0xfff), &exception, NULL);
+ EXPECT_EQ(exception.trapnr, GP_VECTOR);
+ EXPECT_EQ(exception.leaf, ENCLU_EENTER);
}
int main(int argc, char *argv[], char *envp[])
Add a check to verify that an exception on EENTER is correctly reported. Although the type of exception doesn't truly matter, e.g. a page fault is no more or less interesting than a general protection fault, use an unaligned TCS to trigger a #GP to avoid complications 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(+)