Linux-Sgx Archive on lore.kernel.org
 help / color / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: linux-sgx@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>
Subject: [PATCH 3/5] selftests/sgx: Move EINIT out of encl_build()
Date: Mon, 23 Mar 2020 05:46:32 +0200
Message-ID: <20200323034634.4157-3-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20200323034634.4157-1-jarkko.sakkinen@linux.intel.com>

Take EINIT out of encl_build() and move SIGSTRUCT generation and EINIT
right after the encl_build() call. No reason to intertie them as they are
fully independent tasks (i.e. could be even done in parallel).

Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 tools/testing/selftests/sgx/main.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index f39b783c8def..995423565c83 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -195,11 +195,9 @@ static bool encl_add_pages(int dev_fd, unsigned long offset, void *data,
 	(SGX_SECINFO_REG | SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_X)
 
 static bool encl_build(int encl_fd, struct sgx_secs *secs, void *bin,
-		       unsigned long bin_size, struct sgx_sigstruct *sigstruct)
+		       unsigned long bin_size)
 {
-	struct sgx_enclave_init ioc;
 	void *addr;
-	int rc;
 
 	if (!encl_add_pages(encl_fd, 0, bin, PAGE_SIZE, SGX_SECINFO_TCS))
 		return false;
@@ -208,13 +206,6 @@ static bool encl_build(int encl_fd, struct sgx_secs *secs, void *bin,
 			    bin_size - PAGE_SIZE, SGX_REG_PAGE_FLAGS))
 		return false;
 
-	ioc.sigstruct = (uint64_t)sigstruct;
-	rc = ioctl(encl_fd, SGX_IOC_ENCLAVE_INIT, &ioc);
-	if (rc) {
-		fprintf(stderr, "EINIT failed rc=%d\n", rc);
-		return false;
-	}
-
 	addr = mmap((void *)secs->base, PAGE_SIZE, PROT_READ | PROT_WRITE,
 		    MAP_SHARED | MAP_FIXED, encl_fd, 0);
 	if (addr == MAP_FAILED) {
@@ -311,11 +302,13 @@ int main(int argc, char *argv[], char *envp[])
 {
 	struct sgx_enclave_exception exception;
 	struct sgx_sigstruct sigstruct;
+	struct sgx_enclave_init ioc;
 	struct vdso_symtab symtab;
 	Elf64_Sym *eenter_sym;
 	uint64_t result = 0;
 	struct context ctx;
 	void *addr;
+	int ret;
 
 	context_init(&ctx);
 
@@ -328,15 +321,21 @@ int main(int argc, char *argv[], char *envp[])
 	if (!encl_data_map("encl.bin", &ctx.bin, &ctx.bin_size))
 		goto err;
 
-	if (!encl_create_sigstruct(ctx.bin, ctx.bin_size, &sigstruct))
+	if (!encl_create(ctx.encl_fd, ctx.bin_size, &ctx.secs))
 		goto err;
 
-	if (!encl_create(ctx.encl_fd, ctx.bin_size, &ctx.secs))
+	if (!encl_build(ctx.encl_fd, &ctx.secs, ctx.bin, ctx.bin_size))
+		goto err;
+
+	if (!encl_create_sigstruct(ctx.bin, ctx.bin_size, &sigstruct))
 		goto err;
 
-	if (!encl_build(ctx.encl_fd, &ctx.secs, ctx.bin, ctx.bin_size,
-			&sigstruct))
+	ioc.sigstruct = (uint64_t)&sigstruct;
+	ret = ioctl(ctx.encl_fd, SGX_IOC_ENCLAVE_INIT, &ioc);
+	if (ret) {
+		fprintf(stderr, "EINIT failed ret=%d, errno=%d\n", ret, errno);
 		goto err;
+	}
 
 	memset(&exception, 0, sizeof(exception));
 
-- 
2.25.1


  parent reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23  3:46 [PATCH 1/5] selftests/sgx: Add PHDRS to encl.lds Jarkko Sakkinen
2020-03-23  3:46 ` [PATCH 2/5] selftests/sgx: Manage encl_fd in the main function Jarkko Sakkinen
2020-03-23  3:46 ` Jarkko Sakkinen [this message]
2020-03-23  3:46 ` [PATCH 4/5] selftest/sgx: Replace encl_build() with encl_build_segment() Jarkko Sakkinen
2020-03-23  3:46 ` [PATCH 5/5] selftests/sgx: Load encl.elf directly in the test program Jarkko Sakkinen
2020-03-23  3:52 ` [PATCH 1/5] selftests/sgx: Add PHDRS to encl.lds Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200323034634.4157-3-jarkko.sakkinen@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Sgx Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sgx/0 linux-sgx/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sgx linux-sgx/ https://lore.kernel.org/linux-sgx \
		linux-sgx@vger.kernel.org
	public-inbox-index linux-sgx

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sgx


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git