diff mbox series

[for_v37,6/6] selftests/sgx: Add a smoke test to ensure the user handler is invoked

Message ID 20200904104437.29555-7-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series x86/vdso: x86/sgx: Rework SGX vDSO API | expand

Commit Message

Sean Christopherson Sept. 4, 2020, 10:44 a.m. UTC
Add a very simple exit handler and use it as a third variant of the SGX
selftest to verify that the vDSO invokes then user's handler when one is
supplied.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 tools/testing/selftests/sgx/main.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Jarkko Sakkinen Sept. 4, 2020, 2:10 p.m. UTC | #1
On Fri, Sep 04, 2020 at 03:44:37AM -0700, Sean Christopherson wrote:
> Add a very simple exit handler and use it as a third variant of the SGX
> selftest to verify that the vDSO invokes then user's handler when one is
> supplied.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
 
Acked-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

I have no concerns of the vDSO code with these changes have been merged.
The way things are structured ('flags' + the fact we have a context
structure 'run' for everything) keeps door open for eBPF (if ever
wanted).

/Jarkko
diff mbox series

Patch

diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 158ea9e2b6d3a..44acb3c720675 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -137,10 +137,21 @@  int check_result(struct sgx_enclave_run *run, int ret, uint64_t result,
 		printf("FAIL: %s(), expected: 0x%lx, got: 0x%lx\n",
 		       test, MAGIC, result);
 		return -EIO;
+	} else if (run->user_data) {
+		printf("FAIL: %s() user data, expected: 0x0, got: 0x%llx\n",
+		       test, run->user_data);
+		return -EIO;
 	}
 	return 0;
 }
 
+static int exit_handler(long rdi, long rsi, long rdx, long ursp, long r8, long r9,
+			struct sgx_enclave_run *run)
+{
+	run->user_data = 0;
+	return 0;
+}
+
 int main(int argc, char *argv[], char *envp[])
 {
 	struct sgx_enclave_run run;
@@ -203,6 +214,14 @@  int main(int argc, char *argv[], char *envp[])
 	if (check_result(&run, ret, result, "eenter"))
 		goto err;
 
+	/* And with an exit handler. */
+	run.user_handler = exit_handler;
+	run.user_data = 0xdeadbeef;
+	ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER,
+		     0, 0, &run);
+	if (check_result(&run, ret, result, "exit_handler"))
+		goto err;
+
 	printf("SUCCESS\n");
 	encl_delete(&encl);
 	exit(0);