Skip to contentSkip to conversation

selftests/sgx: Rename 'eenter' and 'sgx_call_vdso'

PATCH In review Jarkko Sakkinen 3 participants 18 messages Jun 10, 2021 – Jun 18, 2021

Subsystems (2)
lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH v8 1/5 selftests/sgx: Rename 'eenter' and 'sgx_call_vdso'

Rename symbols for better clarity:

* 'eenter' might be confused for directly calling ENCLU[EENTER]. It does not. It calls into the VDSO, which actually has the EENTER instruction.
* 'sgx_call_vdso' is *only* used for entering the enclave. It's not some generic SGX call into the VDSO.

---

v3:
Refine the commit message according to Dave's suggestions.

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(-)
tools/testing/selftests/sgx/call.S +3 -3
index 4ecadc7490f4..b09a25890f3b 100644
@@ -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
tools/testing/selftests/sgx/main.c +13 -12
index d304a4044eb9..43da68388e25 100644
@@ -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;
 
tools/testing/selftests/sgx/main.h +2 -2
index 67211a708f04..68672fd86cf9 100644
@@ -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 */
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v8 2/5 selftests/sgx: Migrate to kselftest harness

Migrate to kselftest harness. Use a fixture test with enclave initialized and de-initialized for each of the existing three tests, in other words:

1. One FIXTURE() for managing the enclave life-cycle.
2. Three TEST_F()'s, one for each test case.

Dump lines of /proc/self/maps matching "sgx" in FIXTURE_SETUP() as this can be very useful debugging information later on.

---

v8:
* Replace inline function call with ENCL_CALL() macro.

v7:
* Implement encl_call() that wraps the logic of invoking the vDSO for the test enclave.

v6:
* Remove extra '\n' from TH_LOG() calls.

v5:
* Use TH_LOG() for printing enclave address ranges instead of printf(), based on Reinette's remark.

v4:
* Refine to take better use of the kselftest harness macros.
* Fix: TCS base address was not initialized for a run struct.

v3:
* Use helper macros.

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

 tools/testing/selftests/sgx/load.c |   3 -
 tools/testing/selftests/sgx/main.c | 177 +++++++++++++++--------------
 2 files changed, 92 insertions(+), 88 deletions(-)
tools/testing/selftests/sgx/load.c +0 -3
index f441ac34b4d4..00928be57fc4 100644
@@ -239,9 +239,6 @@ bool encl_load(const char *path, struct encl *encl)
 		seg->offset = (phdr->p_offset & PAGE_MASK) - src_offset;
 		seg->size = (phdr->p_filesz + PAGE_SIZE - 1) & PAGE_MASK;
 
-		printf("0x%016lx 0x%016lx 0x%02x\n", seg->offset, seg->size,
-		       seg->prot);
-
 		j++;
 	}
 
tools/testing/selftests/sgx/main.c +92 -85

217 lines not on this page · raw message

Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH v8 3/5 selftests/sgx: Dump enclave memory map

In reply to Jarkko Sakkinen

Often, it's useful to check whether /proc/self/maps looks sane when dealing with memory mapped objects, especially when they are JIT'ish dynamically constructed objects. Therefore, dump "/dev/sgx_enclave" matching lines from the memory map in FIXTURE_SETUP().

---
 tools/testing/selftests/sgx/main.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tools/testing/selftests/sgx/main.c +14 -0
index 6da19b6bf287..14030f8b85ff 100644
@@ -117,6 +117,8 @@ FIXTURE_SETUP(enclave)
 	Elf64_Sym *sgx_enter_enclave_sym = NULL;
 	struct vdso_symtab symtab;
 	struct encl_segment *seg;
+	char maps_line[256];
+	FILE *maps_file;
 	unsigned int i;
 	void *addr;
 
@@ -167,6 +169,18 @@ FIXTURE_SETUP(enclave)
 	memset(&self->run, 0, sizeof(self->run));
 	self->run.tcs = self->encl.encl_base;
 
+	maps_file = fopen("/proc/self/maps", "r");
+	if (maps_file != NULL)  {
+		while (fgets(maps_line, sizeof(maps_line), maps_file) != NULL) {
+			maps_line[strlen(maps_line) - 1] = '\0';
+
+			if (strstr(maps_line, "/dev/sgx_enclave"))
+				TH_LOG("%s", maps_line);
+		}
+
+		fclose(maps_file);
+	}
+
 err:
 	if (!sgx_enter_enclave_sym)
 		encl_delete(&self->encl);
Signature · 1 line
2.31.1
maintainer
#3 lore raw

Re: [PATCH v8 3/5] selftests/sgx: Dump enclave memory map

Quoted 24 lines · Jarkko Sakkinen

Often, it's useful to check whether /proc/self/maps looks sane when dealing with memory mapped objects, especially when they are JIT'ish dynamically constructed objects. Therefore, dump "/dev/sgx_enclave" matching lines from the memory map in FIXTURE_SETUP().

---
  tools/testing/selftests/sgx/main.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
tools/testing/selftests/sgx/main.c +2 -0
index 6da19b6bf287..14030f8b85ff 100644
@@ -117,6 +117,8 @@ FIXTURE_SETUP(enclave)
  	Elf64_Sym *sgx_enter_enclave_sym = NULL;
  	struct vdso_symtab symtab;
  	struct encl_segment *seg;
+	char maps_line[256];
+	FILE *maps_file;
  	unsigned int i;
  	void *addr;
 

tools/testing/selftests/sgx/main.c FIXTURE_SETUP(enclave) · line 172

Quoted 4 lines
tools/testing/selftests/sgx/main.c +1 -0
@@ -167,6 +169,18 @@ FIXTURE_SETUP(enclave)
  	memset(&self->run, 0, sizeof(self->run));
  	self->run.tcs = self->encl.encl_base;
 
+	maps_file = fopen("/proc/self/maps", "r");

I almost applied these. Does this require root access, if so, please add logic to skip the test if non-root user runs it.

Same comments for all other paths that might require root access.

thanks,
-- Shuah

#4 lore raw

Re: [PATCH v8 3/5] selftests/sgx: Dump enclave memory map

Quoted 10 lines · Shuah Khan
Quoted 5 lines

  @@ -167,6 +169,18 @@ FIXTURE_SETUP(enclave)
      memset(&self->run, 0, sizeof(self->run));
      self->run.tcs = self->encl.encl_base;
  +    maps_file = fopen("/proc/self/maps", "r");

I almost applied these. Does this require root access, if so, please add logic to skip the test if non-root user runs it.

Same comments for all other paths that might require root access.

This specifically doesn't require root. Anything can read its own /proc/self/maps file.

author maintainer
#5 lore raw

Re: [PATCH v8 3/5] selftests/sgx: Dump enclave memory map

In reply to Shuah Khan
Quoted 31 lines · Shuah Khan
Quoted 23 lines · Jarkko Sakkinen

Often, it's useful to check whether /proc/self/maps looks sane when dealing with memory mapped objects, especially when they are JIT'ish dynamically constructed objects. Therefore, dump "/dev/sgx_enclave" matching lines from the memory map in FIXTURE_SETUP().

---
  tools/testing/selftests/sgx/main.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
tools/testing/selftests/sgx/main.c +2 -0
index 6da19b6bf287..14030f8b85ff 100644
@@ -117,6 +117,8 @@ FIXTURE_SETUP(enclave)
  	Elf64_Sym *sgx_enter_enclave_sym = NULL;
  	struct vdso_symtab symtab;
  	struct encl_segment *seg;
+	char maps_line[256];
+	FILE *maps_file;
  	unsigned int i;
  	void *addr;

tools/testing/selftests/sgx/main.c FIXTURE_SETUP(enclave) · line 171

Quoted 3 lines
tools/testing/selftests/sgx/main.c +1 -0
@@ -167,6 +169,18 @@ FIXTURE_SETUP(enclave)
  	memset(&self->run, 0, sizeof(self->run));
  	self->run.tcs = self->encl.encl_base;
+	maps_file = fopen("/proc/self/maps", "r");

I almost applied these. Does this require root access, if so, please add logic to skip the test if non-root user runs it.

Quoted 1 line

Same comments for all other paths that might require root access.

As Dave stated, it does not. A process can inspect its own state through /proc/self path. E.g. Chrome web browser uses /proc/self/exe to initialize multiple instances of itself for browser tabs...

As far as other things go, this patch set does not bind to any other new OS resources.

Quoted 2 lines

thanks,
-- Shuah

/Jarkko

maintainer
#6 lore raw

Re: [PATCH v8 3/5] selftests/sgx: Dump enclave memory map

Quoted 32 lines · Jarkko Sakkinen
Quoted 31 lines · Shuah Khan
Quoted 23 lines · Jarkko Sakkinen

Often, it's useful to check whether /proc/self/maps looks sane when dealing with memory mapped objects, especially when they are JIT'ish dynamically constructed objects. Therefore, dump "/dev/sgx_enclave" matching lines from the memory map in FIXTURE_SETUP().

---
   tools/testing/selftests/sgx/main.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
tools/testing/selftests/sgx/main.c +2 -0
index 6da19b6bf287..14030f8b85ff 100644
@@ -117,6 +117,8 @@ FIXTURE_SETUP(enclave)
   	Elf64_Sym *sgx_enter_enclave_sym = NULL;
   	struct vdso_symtab symtab;
   	struct encl_segment *seg;
+	char maps_line[256];
+	FILE *maps_file;
   	unsigned int i;
   	void *addr;

tools/testing/selftests/sgx/main.c FIXTURE_SETUP(enclave) · line 171

Quoted 3 lines
tools/testing/selftests/sgx/main.c +1 -0
@@ -167,6 +169,18 @@ FIXTURE_SETUP(enclave)
   	memset(&self->run, 0, sizeof(self->run));
   	self->run.tcs = self->encl.encl_base;
+	maps_file = fopen("/proc/self/maps", "r");

I almost applied these. Does this require root access, if so, please add logic to skip the test if non-root user runs it.

Quoted 6 lines
Quoted 1 line

Same comments for all other paths that might require root access.

As Dave stated, it does not. A process can inspect its own state through /proc/self path. E.g. Chrome web browser uses /proc/self/exe to initialize multiple instances of itself for browser tabs...

Ah yes. I missed the self part. Thanks for clarifying.

Quoted 3 lines

As far as other things go, this patch set does not bind to any other new OS resources.

Thank you. I will apply these for 5.14-rc1.

thanks,
-- Shuah

author maintainer
#7 lore raw

Re: [PATCH v8 3/5] selftests/sgx: Dump enclave memory map

Quoted 40 lines · Shuah Khan
Quoted 32 lines · Jarkko Sakkinen
Quoted 31 lines · Shuah Khan
Quoted 23 lines · Jarkko Sakkinen

Often, it's useful to check whether /proc/self/maps looks sane when dealing with memory mapped objects, especially when they are JIT'ish dynamically constructed objects. Therefore, dump "/dev/sgx_enclave" matching lines from the memory map in FIXTURE_SETUP().

---
   tools/testing/selftests/sgx/main.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
tools/testing/selftests/sgx/main.c +2 -0
index 6da19b6bf287..14030f8b85ff 100644
@@ -117,6 +117,8 @@ FIXTURE_SETUP(enclave)
   	Elf64_Sym *sgx_enter_enclave_sym = NULL;
   	struct vdso_symtab symtab;
   	struct encl_segment *seg;
+	char maps_line[256];
+	FILE *maps_file;
   	unsigned int i;
   	void *addr;

tools/testing/selftests/sgx/main.c FIXTURE_SETUP(enclave) · line 171

Quoted 3 lines
tools/testing/selftests/sgx/main.c +1 -0
@@ -167,6 +169,18 @@ FIXTURE_SETUP(enclave)
   	memset(&self->run, 0, sizeof(self->run));
   	self->run.tcs = self->encl.encl_base;
+	maps_file = fopen("/proc/self/maps", "r");

I almost applied these. Does this require root access, if so, please add logic to skip the test if non-root user runs it.

Quoted 6 lines
Quoted 1 line

Same comments for all other paths that might require root access.

As Dave stated, it does not. A process can inspect its own state through /proc/self path. E.g. Chrome web browser uses /proc/self/exe to initialize multiple instances of itself for browser tabs...

Quoted 7 lines

Ah yes. I missed the self part. Thanks for clarifying.

Quoted 3 lines

As far as other things go, this patch set does not bind to any other new OS resources.

Thank you. I will apply these for 5.14-rc1.

Thank you!

Quoted 2 lines

thanks,
-- Shuah

/Jarkko

author maintainer
#8 lore raw

PATCH v8 4/5 selftests/sgx: Add EXPECT_EEXIT() macro

In reply to Jarkko Sakkinen

Add EXPECT_EEXIT() macro, which will conditionally print the exception information, in addition to

  EXPECT_EQ(self->run.function, EEXIT);
---
 tools/testing/selftests/sgx/main.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
tools/testing/selftests/sgx/main.c +11 -3
index 14030f8b85ff..bcd0257f48e0 100644
@@ -205,6 +205,14 @@ FIXTURE_TEARDOWN(enclave)
 		ret; \
 	})
 
+#define EXPECT_EEXIT(run) \
+	do { \
+		EXPECT_EQ((run)->function, EEXIT); \
+		if ((run)->function != EEXIT) \
+			TH_LOG("0x%02x 0x%02x 0x%016llx", (run)->exception_vector, \
+			       (run)->exception_error_code, (run)->exception_addr); \
+	} while (0)
+
 TEST_F(enclave, unclobbered_vdso)
 {
 	uint64_t result = 0;
@@ -212,7 +220,7 @@ TEST_F(enclave, unclobbered_vdso)
 	EXPECT_EQ(ENCL_CALL(&MAGIC, &result, &self->run, false), 0);
 
 	EXPECT_EQ(result, MAGIC);
-	EXPECT_EQ(self->run.function, EEXIT);
+	EXPECT_EEXIT(&self->run);
 	EXPECT_EQ(self->run.user_data, 0);
 }
 
@@ -223,7 +231,7 @@ TEST_F(enclave, clobbered_vdso)
 	EXPECT_EQ(ENCL_CALL(&MAGIC, &result, &self->run, true), 0);
 
 	EXPECT_EQ(result, MAGIC);
-	EXPECT_EQ(self->run.function, EEXIT);
+	EXPECT_EEXIT(&self->run);
 	EXPECT_EQ(self->run.user_data, 0);
 }
 
@@ -245,7 +253,7 @@ TEST_F(enclave, clobbered_vdso_and_user_function)
 	EXPECT_EQ(ENCL_CALL(&MAGIC, &result, &self->run, true), 0);
 
 	EXPECT_EQ(result, MAGIC);
-	EXPECT_EQ(self->run.function, EEXIT);
+	EXPECT_EEXIT(&self->run);
 	EXPECT_EQ(self->run.user_data, 0);
 }
 
Signature · 1 line
2.31.1
author maintainer
#9 lore raw

PATCH v8 5/5 selftests/sgx: Refine the test enclave to have storage

In reply to Jarkko Sakkinen

Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET. ENCL_OP_PUT stores value inside the enclave address space and ENCL_OP_GET reads it. The internal buffer can be later extended to be variable size, and allow reclaimer tests.

---
 tools/testing/selftests/sgx/defines.h     | 10 ++++
 tools/testing/selftests/sgx/main.c        | 57 ++++++++++++++++++-----
 tools/testing/selftests/sgx/test_encl.c   | 19 +++++++-
 tools/testing/selftests/sgx/test_encl.lds |  3 +-
 4 files changed, 74 insertions(+), 15 deletions(-)
tools/testing/selftests/sgx/defines.h +10 -0
index 0bd73428d2f3..f88562afcaa0 100644
@@ -18,4 +18,14 @@
 #include "../../../../arch/x86/include/asm/enclu.h"
 #include "../../../../arch/x86/include/uapi/asm/sgx.h"
 
+enum encl_op_type {
+	ENCL_OP_PUT,
+	ENCL_OP_GET,
+};
+
+struct encl_op {
+	uint64_t type;
+	uint64_t buffer;
+};
+
 #endif /* DEFINES_H */
tools/testing/selftests/sgx/main.c +45 -12

95 lines not on this page · raw message

tools/testing/selftests/sgx/test_encl.c +17 -2
index cf25b5dc1e03..734ea52f9924 100644
@@ -4,6 +4,8 @@
 #include <stddef.h>
 #include "defines.h"
 
+static uint8_t encl_buffer[8192] = { 1 };
+
 static void *memcpy(void *dest, const void *src, size_t n)
 {
 	size_t i;
@@ -14,7 +16,20 @@ static void *memcpy(void *dest, const void *src, size_t n)
 	return dest;
 }
 
-void encl_body(void *rdi, void *rsi)
+void encl_body(void *rdi,  void *rsi)
 {
-	memcpy(rsi, rdi, 8);
+	struct encl_op *op = (struct encl_op *)rdi;
+
+	switch (op->type) {
+	case ENCL_OP_PUT:
+		memcpy(&encl_buffer[0], &op->buffer, 8);
+		break;
+
+	case ENCL_OP_GET:
+		memcpy(&op->buffer, &encl_buffer[0], 8);
+		break;
+
+	default:
+		break;
+	}
 }
tools/testing/selftests/sgx/test_encl.lds +2 -1
index 0fbbda7e665e..a1ec64f7d91f 100644
@@ -18,9 +18,10 @@ SECTIONS
 	.text : {
 		*(.text*)
 		*(.rodata*)
+		FILL(0xDEADBEEF);
+		. = ALIGN(4096);
 	} : text
 
-	. = ALIGN(4096);
 	.data : {
 		*(.data*)
 	} : data
Signature · 1 line
2.31.1
maintainer
#10 lore raw

Re: [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage

Quoted 5 lines · Jarkko Sakkinen

Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET. ENCL_OP_PUT stores value inside the enclave address space and ENCL_OP_GET reads it. The internal buffer can be later extended to be variable size, and allow reclaimer tests.

Quoted 8 lines
---
  tools/testing/selftests/sgx/defines.h     | 10 ++++
  tools/testing/selftests/sgx/main.c        | 57 ++++++++++++++++++-----
  tools/testing/selftests/sgx/test_encl.c   | 19 +++++++-
  tools/testing/selftests/sgx/test_encl.lds |  3 +-
  4 files changed, 74 insertions(+), 15 deletions(-)

Test output before applying the series:

TAP version 13
1..1
# selftests: sgx: test_sgx
# Unable to open /dev/sgx_enclave: No such file or directory # 1..0 # SKIP cannot load enclaves
ok 1 selftests: sgx: test_sgx # SKIP

Test output after applying second patch

selftests/sgx: Migrate to kselftest harness

Output changes to the following. It doesn't look like the second patch adds any new tests. What is the point in running the tests that fail if /dev/sgx_enclave is missing.

Unfortunately this series doesn't have a cover letter that explains what this series is doing. I don't like the fact that the test output and behavior changes when migrating the test to kselftest harness. Shouldn't the output stay the same as in skip the tests if /dev/sgx_enclave fails.

TAP version 13
1..1
# selftests: sgx: test_sgx
# TAP version 13
# 1..3
# # Starting 3 tests from 2 test cases.
# # RUN enclave.unclobbered_vdso ...
# Unable to open /dev/sgx_enclave: No such file or directory

# ok 2 # SKIP cannot load enclaves
# # Planned tests != run tests (3 != 1)
# # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
# # unclobbered_vdso: Test failed at step #4
# #          FAIL  enclave.unclobbered_vdso
# not ok 1 enclave.unclobbered_vdso
# #  RUN           enclave.clobbered_vdso ...
# Unable to open /dev/sgx_enclave: No such file or directory
# ok 3 # SKIP cannot load enclaves
# # Planned tests != run tests (3 != 2)
# # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:1 error:0
# # clobbered_vdso: Test failed at step #4
# #          FAIL  enclave.clobbered_vdso
# not ok 2 enclave.clobbered_vdso
# #  RUN           enclave.clobbered_vdso_and_user_function ...
# Unable to open /dev/sgx_enclave: No such file or directory
# ok 4 # SKIP cannot load enclaves
# # Totals: pass:0 fail:2 xfail:0 xpass:0 skip:1 error:0
# # clobbered_vdso_and_user_function: Test failed at step #4
# #          FAIL  enclave.clobbered_vdso_and_user_function
# not ok 3 enclave.clobbered_vdso_and_user_function
# # FAILED: 0 / 3 tests passed.
# # Totals: pass:0 fail:3 xfail:0 xpass:0 skip:0 error:0
not ok 1 selftests: sgx: test_sgx # exit=1

thanks,
-- Shuah

author maintainer
#11 lore raw

Re: [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage

Quoted 32 lines · Shuah Khan
Quoted 5 lines · Jarkko Sakkinen

Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET. ENCL_OP_PUT stores value inside the enclave address space and ENCL_OP_GET reads it. The internal buffer can be later extended to be variable size, and allow reclaimer tests.

Quoted 8 lines
---
  tools/testing/selftests/sgx/defines.h     | 10 ++++
  tools/testing/selftests/sgx/main.c        | 57 ++++++++++++++++++-----
  tools/testing/selftests/sgx/test_encl.c   | 19 +++++++-
  tools/testing/selftests/sgx/test_encl.lds |  3 +-
  4 files changed, 74 insertions(+), 15 deletions(-)

Test output before applying the series:

TAP version 13
1..1
# selftests: sgx: test_sgx
# Unable to open /dev/sgx_enclave: No such file or directory # 1..0 # SKIP cannot load enclaves
ok 1 selftests: sgx: test_sgx # SKIP

Test output after applying second patch

selftests/sgx: Migrate to kselftest harness

Output changes to the following. It doesn't look like the second patch adds any new tests. What is the point in running the tests that fail if /dev/sgx_enclave is missing.

Quoted 5 lines

Unfortunately this series doesn't have a cover letter that explains what this series is doing. I don't like the fact that the test output and behavior changes when migrating the test to kselftest harness. Shouldn't the output stay the same as in skip the tests if /dev/sgx_enclave fails.

I get what you are saying but actually I do not know how with fixtures I can skip "the rest" when FIXTURE_SETUP() fails.

The reason for the output below is that with fixtures for all tests enclave is initialized for each test case. And it kind of makes sense because all tests start from the clean expected state.

I don't how to do that with zero change in the output.

The reason to do this change is to make it easy to add more tests, and return correct status codes to the framework.

Quoted 33 lines

TAP version 13
1..1
# selftests: sgx: test_sgx
# TAP version 13
# 1..3
# # Starting 3 tests from 2 test cases.
# # RUN enclave.unclobbered_vdso ...
# Unable to open /dev/sgx_enclave: No such file or directory

# ok 2 # SKIP cannot load enclaves
# # Planned tests != run tests (3 != 1)
# # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
# # unclobbered_vdso: Test failed at step #4
# #          FAIL  enclave.unclobbered_vdso
# not ok 1 enclave.unclobbered_vdso
# #  RUN           enclave.clobbered_vdso ...
# Unable to open /dev/sgx_enclave: No such file or directory
# ok 3 # SKIP cannot load enclaves
# # Planned tests != run tests (3 != 2)
# # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:1 error:0
# # clobbered_vdso: Test failed at step #4
# #          FAIL  enclave.clobbered_vdso
# not ok 2 enclave.clobbered_vdso
# #  RUN           enclave.clobbered_vdso_and_user_function ...
# Unable to open /dev/sgx_enclave: No such file or directory
# ok 4 # SKIP cannot load enclaves
# # Totals: pass:0 fail:2 xfail:0 xpass:0 skip:1 error:0
# # clobbered_vdso_and_user_function: Test failed at step #4
# #          FAIL  enclave.clobbered_vdso_and_user_function
# not ok 3 enclave.clobbered_vdso_and_user_function
# # FAILED: 0 / 3 tests passed.
# # Totals: pass:0 fail:3 xfail:0 xpass:0 skip:0 error:0
not ok 1 selftests: sgx: test_sgx # exit=1
Quoted 2 lines

thanks,
-- Shuah

/Jarkko

author maintainer
#12 lore raw

Re: [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage

Quoted 47 lines · Jarkko Sakkinen
Quoted 32 lines · Shuah Khan
Quoted 5 lines · Jarkko Sakkinen

Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET. ENCL_OP_PUT stores value inside the enclave address space and ENCL_OP_GET reads it. The internal buffer can be later extended to be variable size, and allow reclaimer tests.

Quoted 8 lines
---
  tools/testing/selftests/sgx/defines.h     | 10 ++++
  tools/testing/selftests/sgx/main.c        | 57 ++++++++++++++++++-----
  tools/testing/selftests/sgx/test_encl.c   | 19 +++++++-
  tools/testing/selftests/sgx/test_encl.lds |  3 +-
  4 files changed, 74 insertions(+), 15 deletions(-)

Test output before applying the series:

TAP version 13
1..1
# selftests: sgx: test_sgx
# Unable to open /dev/sgx_enclave: No such file or directory # 1..0 # SKIP cannot load enclaves
ok 1 selftests: sgx: test_sgx # SKIP

Test output after applying second patch

selftests/sgx: Migrate to kselftest harness

Output changes to the following. It doesn't look like the second patch adds any new tests. What is the point in running the tests that fail if /dev/sgx_enclave is missing.

Quoted 5 lines

Unfortunately this series doesn't have a cover letter that explains what this series is doing. I don't like the fact that the test output and behavior changes when migrating the test to kselftest harness. Shouldn't the output stay the same as in skip the tests if /dev/sgx_enclave fails.

I get what you are saying but actually I do not know how with fixtures I can skip "the rest" when FIXTURE_SETUP() fails.

The reason for the output below is that with fixtures for all tests enclave is initialized for each test case. And it kind of makes sense because all tests start from the clean expected state.

Quoted 4 lines

I don't how to do that with zero change in the output.

The reason to do this change is to make it easy to add more tests, and return correct status codes to the framework.

To add: everything I did I based purely to the existing kernel documentation, following the examples on how to use fixture.

/Jarkko

maintainer
#13 lore raw

Re: [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage

Quoted 43 lines · Jarkko Sakkinen
Quoted 42 lines · Jarkko Sakkinen
Quoted 32 lines · Shuah Khan
Quoted 5 lines · Jarkko Sakkinen

Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET. ENCL_OP_PUT stores value inside the enclave address space and ENCL_OP_GET reads it. The internal buffer can be later extended to be variable size, and allow reclaimer tests.

Quoted 8 lines
---
   tools/testing/selftests/sgx/defines.h     | 10 ++++
   tools/testing/selftests/sgx/main.c        | 57 ++++++++++++++++++-----
   tools/testing/selftests/sgx/test_encl.c   | 19 +++++++-
   tools/testing/selftests/sgx/test_encl.lds |  3 +-
   4 files changed, 74 insertions(+), 15 deletions(-)

Test output before applying the series:

TAP version 13
1..1
# selftests: sgx: test_sgx
# Unable to open /dev/sgx_enclave: No such file or directory # 1..0 # SKIP cannot load enclaves
ok 1 selftests: sgx: test_sgx # SKIP

Test output after applying second patch

selftests/sgx: Migrate to kselftest harness

Output changes to the following. It doesn't look like the second patch adds any new tests. What is the point in running the tests that fail if /dev/sgx_enclave is missing.

Quoted 5 lines

Unfortunately this series doesn't have a cover letter that explains what this series is doing. I don't like the fact that the test output and behavior changes when migrating the test to kselftest harness. Shouldn't the output stay the same as in skip the tests if /dev/sgx_enclave fails.

I get what you are saying but actually I do not know how with fixtures I can skip "the rest" when FIXTURE_SETUP() fails.

Quoted 7 lines
Quoted 7 lines

The reason for the output below is that with fixtures for all tests enclave is initialized for each test case. And it kind of makes sense because all tests start from the clean expected state.

I don't how to do that with zero change in the output.

Yeah. I took a look at the FIXTURE. Doesn't look like it is possible.

Quoted 6 lines
Quoted 2 lines

The reason to do this change is to make it easy to add more tests, and return correct status codes to the framework.

To add: everything I did I based purely to the existing kernel documentation, following the examples on how to use fixture.

I will pick these up and will add a note to the last commit that output changes, so test rings that run kselftest are aware of the change.

thanks,
-- Shuah

author maintainer
#14 lore raw

Re: [PATCH v8 5/5] selftests/sgx: Refine the test enclave to have storage

Quoted 61 lines · Shuah Khan
Quoted 43 lines · Jarkko Sakkinen
Quoted 42 lines · Jarkko Sakkinen
Quoted 32 lines · Shuah Khan
Quoted 5 lines · Jarkko Sakkinen

Extend the enclave to have two operations: ENCL_OP_PUT and ENCL_OP_GET. ENCL_OP_PUT stores value inside the enclave address space and ENCL_OP_GET reads it. The internal buffer can be later extended to be variable size, and allow reclaimer tests.

Quoted 8 lines
---
   tools/testing/selftests/sgx/defines.h     | 10 ++++
   tools/testing/selftests/sgx/main.c        | 57 ++++++++++++++++++-----
   tools/testing/selftests/sgx/test_encl.c   | 19 +++++++-
   tools/testing/selftests/sgx/test_encl.lds |  3 +-
   4 files changed, 74 insertions(+), 15 deletions(-)

Test output before applying the series:

TAP version 13
1..1
# selftests: sgx: test_sgx
# Unable to open /dev/sgx_enclave: No such file or directory # 1..0 # SKIP cannot load enclaves
ok 1 selftests: sgx: test_sgx # SKIP

Test output after applying second patch

selftests/sgx: Migrate to kselftest harness

Output changes to the following. It doesn't look like the second patch adds any new tests. What is the point in running the tests that fail if /dev/sgx_enclave is missing.

Quoted 5 lines

Unfortunately this series doesn't have a cover letter that explains what this series is doing. I don't like the fact that the test output and behavior changes when migrating the test to kselftest harness. Shouldn't the output stay the same as in skip the tests if /dev/sgx_enclave fails.

I get what you are saying but actually I do not know how with fixtures I can skip "the rest" when FIXTURE_SETUP() fails.

Quoted 7 lines
Quoted 7 lines

The reason for the output below is that with fixtures for all tests enclave is initialized for each test case. And it kind of makes sense because all tests start from the clean expected state.

I don't how to do that with zero change in the output.

Yeah. I took a look at the FIXTURE. Doesn't look like it is possible.

Quoted 6 lines
Quoted 2 lines

The reason to do this change is to make it easy to add more tests, and return correct status codes to the framework.

To add: everything I did I based purely to the existing kernel documentation, following the examples on how to use fixture.

Quoted 6 lines

I will pick these up and will add a note to the last commit that output changes, so test rings that run kselftest are aware of the change.

thanks,
-- Shuah

OK, great, thank you!

/Jarkko

#15 lore raw
In reply to Jarkko Sakkinen
Quoted 8 lines · Jarkko Sakkinen

Rename symbols for better clarity:

* 'eenter' might be confused for directly calling ENCLU[EENTER]. It does not. It calls into the VDSO, which actually has the EENTER instruction.
* 'sgx_call_vdso' is *only* used for entering the enclave. It's not some generic SGX call into the VDSO.

These all look fine to me. Feel free to add my ack on them.

Since these are pure x86 selftests and the initial code went through the x86 maintainers, should these got through them as well? Or, since this is only selftest code, should Shuah pick them up?

maintainer
#16 lore raw
Quoted 8 lines · Dave Hansen
Quoted 7 lines · Jarkko Sakkinen

Rename symbols for better clarity:

* 'eenter' might be confused for directly calling ENCLU[EENTER]. It does not. It calls into the VDSO, which actually has the EENTER instruction.
* 'sgx_call_vdso' is *only* used for entering the enclave. It's not some generic SGX call into the VDSO.

Quoted 8 lines
Quoted 1 line

These all look fine to me. Feel free to add my ack on them.

Since these are pure x86 selftests and the initial code went through the x86 maintainers, should these got through them as well? Or, since this is only selftest code, should Shuah pick them up?

I will queue these up for 5.14-rc1

thanks,
-- Shuah

maintainer
#17 lore raw
Quoted 11 lines · Shuah Khan
Quoted 10 lines · Dave Hansen
Quoted 8 lines · Jarkko Sakkinen

Rename symbols for better clarity:

* 'eenter' might be confused for directly calling ENCLU[EENTER].  It does not.  It calls into the VDSO, which actually has the EENTER instruction.
* 'sgx_call_vdso' is *only* used for entering the enclave.  It's not some generic SGX call into the VDSO.

Quoted 9 lines
Quoted 6 lines

These all look fine to me.  Feel free to add my ack on them.

Since these are pure x86 selftests and the initial code went through the x86 maintainers, should these got through them as well?  Or, since this is only selftest code, should Shuah pick them up?

I will queue these up for 5.14-rc1

I almost applied these. Does this require root access, if so, please add logic to skip the test if non-root user runs it.

Please check for code paths that require root access and skip the tests.

thanks,
-- Shuah