[for_v2?,v2,11/14] selftests/x86/sgx: Add a check on the vDSO exception reporting mechanism
diff mbox series

Message ID 20191017030340.18301-12-sean.j.christopherson@intel.com
State New
Headers show
Series
  • selftests/x86/sgx: Improve tests
Related show

Commit Message

Sean Christopherson Oct. 17, 2019, 3:03 a.m. UTC
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(+)

Patch
diff mbox series

diff --git a/tools/testing/selftests/x86/sgx/defines.h b/tools/testing/selftests/x86/sgx/defines.h
index 1e67f2f29f42..b303bcaeb8dd 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 /* DEFINES_H */
diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c
index 24647050657a..56e13ae4f1ce 100644
--- a/tools/testing/selftests/x86/sgx/main.c
+++ b/tools/testing/selftests/x86/sgx/main.c
@@ -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[])