linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso'
@ 2021-05-06  5:55 Jarkko Sakkinen
  2021-05-06  5:55 ` [PATCH v2 2/2] selftests/sgx: Report kselftest results Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Jarkko Sakkinen @ 2021-05-06  5:55 UTC (permalink / raw)
  To: Shuah Khan
  Cc: linux-sgx, dave.hansen, Jarkko Sakkinen, Dave Hansen,
	linux-kselftest, linux-kernel

Rename symbols for better clarity:

* 'eenter' -> 'vdso_sgx_enter_enclave'
* 'sgx_call_vdso' -> 'sgx_enter_enclave'

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---

v2:
Refined the renames just a bit.

 tools/testing/selftests/sgx/call.S |  6 +++---
 tools/testing/selftests/sgx/main.c | 25 +++++++++++++------------
 tools/testing/selftests/sgx/main.h |  4 ++--
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/tools/testing/selftests/sgx/call.S b/tools/testing/selftests/sgx/call.S
index 4ecadc7490f4..b09a25890f3b 100644
--- a/tools/testing/selftests/sgx/call.S
+++ b/tools/testing/selftests/sgx/call.S
@@ -5,8 +5,8 @@
 
 	.text
 
-	.global sgx_call_vdso
-sgx_call_vdso:
+	.global sgx_enter_enclave
+sgx_enter_enclave:
 	.cfi_startproc
 	push	%r15
 	.cfi_adjust_cfa_offset	8
@@ -27,7 +27,7 @@ sgx_call_vdso:
 	.cfi_adjust_cfa_offset	8
 	push	0x38(%rsp)
 	.cfi_adjust_cfa_offset	8
-	call	*eenter(%rip)
+	call	*vdso_sgx_enter_enclave(%rip)
 	add	$0x10, %rsp
 	.cfi_adjust_cfa_offset	-0x10
 	pop	%rbx
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index d304a4044eb9..43da68388e25 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -21,7 +21,7 @@
 #include "../kselftest.h"
 
 static const uint64_t MAGIC = 0x1122334455667788ULL;
-vdso_sgx_enter_enclave_t eenter;
+vdso_sgx_enter_enclave_t vdso_sgx_enter_enclave;
 
 struct vdso_symtab {
 	Elf64_Sym *elf_symtab;
@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
 {
 	struct sgx_enclave_run run;
 	struct vdso_symtab symtab;
-	Elf64_Sym *eenter_sym;
+	Elf64_Sym *sgx_enter_enclave_sym;
 	uint64_t result = 0;
 	struct encl encl;
 	unsigned int i;
@@ -194,29 +194,30 @@ int main(int argc, char *argv[])
 	if (!vdso_get_symtab(addr, &symtab))
 		goto err;
 
-	eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave");
-	if (!eenter_sym)
+	sgx_enter_enclave_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave");
+	if (!sgx_enter_enclave_sym)
 		goto err;
 
-	eenter = addr + eenter_sym->st_value;
+	vdso_sgx_enter_enclave = addr + sgx_enter_enclave_sym->st_value;
 
-	ret = sgx_call_vdso((void *)&MAGIC, &result, 0, EENTER, NULL, NULL, &run);
-	if (!report_results(&run, ret, result, "sgx_call_vdso"))
+	ret = sgx_enter_enclave((void *)&MAGIC, &result, 0, EENTER,
+					    NULL, NULL, &run);
+	if (!report_results(&run, ret, result, "sgx_enter_enclave_unclobbered"))
 		goto err;
 
 
 	/* Invoke the vDSO directly. */
 	result = 0;
-	ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER,
-		     0, 0, &run);
-	if (!report_results(&run, ret, result, "eenter"))
+	ret = vdso_sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result,
+				     0, EENTER, 0, 0, &run);
+	if (!report_results(&run, ret, result, "sgx_enter_enclave"))
 		goto err;
 
 	/* And with an exit handler. */
 	run.user_handler = (__u64)user_handler;
 	run.user_data = 0xdeadbeef;
-	ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER,
-		     0, 0, &run);
+	ret = vdso_sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result,
+				     0, EENTER, 0, 0, &run);
 	if (!report_results(&run, ret, result, "user_handler"))
 		goto err;
 
diff --git a/tools/testing/selftests/sgx/main.h b/tools/testing/selftests/sgx/main.h
index 67211a708f04..68672fd86cf9 100644
--- a/tools/testing/selftests/sgx/main.h
+++ b/tools/testing/selftests/sgx/main.h
@@ -35,7 +35,7 @@ bool encl_load(const char *path, struct encl *encl);
 bool encl_measure(struct encl *encl);
 bool encl_build(struct encl *encl);
 
-int sgx_call_vdso(void *rdi, void *rsi, long rdx, u32 function, void *r8, void *r9,
-		  struct sgx_enclave_run *run);
+int sgx_enter_enclave(void *rdi, void *rsi, long rdx, u32 function, void *r8, void *r9,
+		      struct sgx_enclave_run *run);
 
 #endif /* MAIN_H */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] selftests/sgx: Report kselftest results
  2021-05-06  5:55 [PATCH v2 1/2] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso' Jarkko Sakkinen
@ 2021-05-06  5:55 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2021-05-06  5:55 UTC (permalink / raw)
  To: Shuah Khan
  Cc: linux-sgx, dave.hansen, Jarkko Sakkinen, Dave Hansen,
	linux-kselftest, linux-kernel

Use ksft API documented in tools/testing/selftests/kselftest.h to count
succeeded and failed tests and print all the debug output with
ksft_print_msg(), as advised by the documentation.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---

v2:
* Add the missing string argument for the test case to
  ksft_test_result_pass() and ksft_test_result_fail() calls.

 tools/testing/selftests/sgx/main.c | 48 +++++++++++++++++-------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 43da68388e25..d61db69f65c6 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -20,6 +20,8 @@
 #include "main.h"
 #include "../kselftest.h"
 
+#define NR_KSELFTESTS 3
+
 static const uint64_t MAGIC = 0x1122334455667788ULL;
 vdso_sgx_enter_enclave_t vdso_sgx_enter_enclave;
 
@@ -107,34 +109,35 @@ static Elf64_Sym *vdso_symtab_get(struct vdso_symtab *symtab, const char *name)
 	return NULL;
 }
 
-bool report_results(struct sgx_enclave_run *run, int ret, uint64_t result,
-		  const char *test)
+bool update_ksft(struct sgx_enclave_run *run, int ret, uint64_t result, const char *test)
 {
 	bool valid = true;
 
 	if (ret) {
-		printf("FAIL: %s() returned: %d\n", test, ret);
+		ksft_print_msg("%s: ret = %d\n", test, ret);
 		valid = false;
 	}
 
 	if (run->function != EEXIT) {
-		printf("FAIL: %s() function, expected: %u, got: %u\n", test, EEXIT,
-		       run->function);
+		ksft_print_msg("%s: function, expected: %u, got: %u\n", test, EEXIT, run->function);
 		valid = false;
 	}
 
 	if (result != MAGIC) {
-		printf("FAIL: %s(), expected: 0x%lx, got: 0x%lx\n", test, MAGIC,
-		       result);
+		ksft_print_msg("%s: expected: 0x%lx, got: 0x%lx\n", test, MAGIC, result);
 		valid = false;
 	}
 
 	if (run->user_data) {
-		printf("FAIL: %s() user data, expected: 0x0, got: 0x%llx\n",
-		       test, run->user_data);
+		ksft_print_msg("%s: user data, expected: 0x0, got: 0x%llx\n", test, run->user_data);
 		valid = false;
 	}
 
+	if (valid)
+		ksft_test_result_pass("%s", test);
+	else
+		ksft_test_result_fail("%s", test);
+
 	return valid;
 }
 
@@ -156,6 +159,9 @@ int main(int argc, char *argv[])
 	void *addr;
 	int ret;
 
+	ksft_print_header();
+	ksft_set_plan(NR_KSELFTESTS);
+
 	memset(&run, 0, sizeof(run));
 
 	if (!encl_load("test_encl.elf", &encl)) {
@@ -178,8 +184,8 @@ int main(int argc, char *argv[])
 		addr = mmap((void *)encl.encl_base + seg->offset, seg->size,
 			    seg->prot, MAP_SHARED | MAP_FIXED, encl.fd, 0);
 		if (addr == MAP_FAILED) {
-			perror("mmap() segment failed");
-			exit(KSFT_FAIL);
+			ksft_print_msg("mmap() segment: %s", strerror(errno));
+			goto err;
 		}
 	}
 
@@ -200,32 +206,32 @@ int main(int argc, char *argv[])
 
 	vdso_sgx_enter_enclave = addr + sgx_enter_enclave_sym->st_value;
 
+	/* 1: unclobbered vDSO */
 	ret = sgx_enter_enclave((void *)&MAGIC, &result, 0, EENTER,
-					    NULL, NULL, &run);
-	if (!report_results(&run, ret, result, "sgx_enter_enclave_unclobbered"))
+				NULL, NULL, &run);
+	if (!update_ksft(&run, ret, result, "unclobbered"))
 		goto err;
 
-
-	/* Invoke the vDSO directly. */
+	/* 2: clobbered vDSO */
 	result = 0;
 	ret = vdso_sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result,
 				     0, EENTER, 0, 0, &run);
-	if (!report_results(&run, ret, result, "sgx_enter_enclave"))
+	if (!update_ksft(&run, ret, result, "sgx_enter_enclave"))
 		goto err;
 
-	/* And with an exit handler. */
+	/* 3: clobbered vDSO with a callback. */
 	run.user_handler = (__u64)user_handler;
 	run.user_data = 0xdeadbeef;
+
 	ret = vdso_sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result,
 				     0, EENTER, 0, 0, &run);
-	if (!report_results(&run, ret, result, "user_handler"))
+	if (!update_ksft(&run, ret, result, "user_handler"))
 		goto err;
 
-	printf("SUCCESS\n");
 	encl_delete(&encl);
-	exit(KSFT_PASS);
+	ksft_exit_pass();
 
 err:
 	encl_delete(&encl);
-	exit(KSFT_FAIL);
+	ksft_exit_fail();
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-06  5:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06  5:55 [PATCH v2 1/2] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso' Jarkko Sakkinen
2021-05-06  5:55 ` [PATCH v2 2/2] selftests/sgx: Report kselftest results Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).